aimstil  5.0.5
geometrics.h
Go to the documentation of this file.
1 #ifndef GEOMETRICS_H_
2 #define GEOMETRICS_H_
3 
5 
6 // includes from TIL
7 #include "til/numeric_array.h"
8 
9 // includes from TIL
10 #include "fuzzy_logic.h"
11 #include "miscUtils.h"
12 
13 
14 namespace til { namespace geo
15 {
16 
17  //-----------------------------------//
18  // Small handy geometric functions //
19  //-----------------------------------//
20 
21  //---------------------------------------------------------------------------
22 
26  template < typename T >
27  inline T herons_formula(T a, T b, T c);
28 
29  //---------------------------------------------------------------------------
30 
34  template < typename T >
35  inline T herons_formula(numeric_array<T,3> const & lengths);
36 
37  //---------------------------------------------------------------------------
38 
40  template < typename T >
41  inline T law_of_cosines(T a, T b, T c);
42 
43  //---------------------------------------------------------------------------
44 
47  template < typename T >
48  inline T law_of_tangents(T a, T b, T c, T area);
49 
50  //---------------------------------------------------------------------------
51 
54  template < typename T >
55  inline T law_of_tangents(T a, T b, T c);
56 
57  //---------------------------------------------------------------------------
58 
62  template < typename T >
63  inline T angle(T x, T y, T norm);
64 
65  //---------------------------------------------------------------------------
66 
68  template < typename T >
69  inline T angle(T x, T y);
70 
71  //---------------------------------------------------------------------------
72 
74  template < typename T >
75  void cartesian2spherical(T x, T y, T z, T & theta, T & phi, T & rho);
76 
77  //---------------------------------------------------------------------------
78 
80  // NB: I put an inline here in the hope that when a rho=1 is passed as an argument,
81  // multiplications whith rho will be dropped.
82  template < typename T >
83  inline void spherical2cartesian(T theta, T phi, T rho, T & x, T & y, T & z);
84 
85  //---------------------------------------------------------------------------
86 
87  //--------------------//
88  // Triangle2Segment //
89  //--------------------//
90 
94  template < typename TArray >
96  {
97  public: // typedef
98  typedef typename TArray::value_type prec_type;
99 
100  public: // functions
101 
103  bool operator()
104  (
105  const TArray & A,
106  const TArray & B,
107  const TArray & C,
108  TArray & X,
109  TArray & Y
110  );
111 
112  private: // functions
113 
114  void doit
115  (
116  const TArray & A,
117  const TArray & B,
118  const TArray & C,
119  TArray & X,
120  TArray & Y
121  );
122 
123  private: // data
124  TArray m_N;
125  };
126 
127  //---------------------------------------------------------------------------
128 
129  template < typename TArray >
130  bool triangle2segment(const TArray & A, const TArray & B, const TArray & C, TArray & X, TArray & Y)
131  {
132  return Triangle2Segment<TArray>()(A, B, C, X, Y);
133  }
134 
135  //---------------------------------------------------------------------------
136 
137  //------------------//
138  // TriangleNormal //
139  //------------------//
140 
143  //template < typename TArray, typename TPrec, typename TResArray = typename change_precision<TArray, TPrec>::type >
144  template < typename TArray, typename TResArray >
146  {
147  public: // exceptions
150  class InvalidTriangle : public std::exception {};
151  public: // typedefs
152  //typedef typename TArray::value_type prec_type;
153  //typedef TPrec prec_type;
154  typedef typename TResArray::value_type prec_type;
155  //typedef typename change_precision<TArray, TPrec>::type TPrecArray;
156  public: // functions
157 
160  bool operator()
161  (
162  const TArray & A,
163  const TArray & B,
164  const TArray & C,
165  TResArray & N
166  );
167  };
168 
169 
170  //---------------------------------------------------------------------------
171 
173  /*
174  template < typename TPrec, typename TArray >
175  typename change_precision<TArray, TPrec>::type
176  triangle_normal(const TArray & A, const TArray & B, const TArray & C)
177  {
178  return TriangleNormal<TArray,TPrec,typename change_precision<TArray, TPrec>::type>()(A,B,C);
179  }
180  */
181 
182  //---------------------------------------------------------------------------
183 
184  template < typename TArray, typename TResArray >
185  //typename change_precision<TArray, TPrec>::type
186  bool
187  triangle_normal(const TArray & A, const TArray & B, const TArray & C, TResArray & result);
188 
189  //---------------------------------------------------------------------------
190 
191  namespace
192  {
193  template < typename TNormal, typename TPoint >
194  inline void normal2D(const TPoint & A, const TPoint & B, TNormal & N)
195  {
196  N[0] = A[1] - B[1];
197  N[1] = B[0] - A[0];
198  }
199  }
200 
201 
202  //---------------------------------------------------------------------------
203 
204  //----------------//
205  // IsIncludedIn //
206  //----------------//
207 
210  {
212  template < typename TArray >
214  {
215  public: // typedefs
216  typedef typename TArray::value_type prec_type;
217  public: // functions
218  bool operator()
219  (
220  const TArray & P,
221  const TArray & A,
222  const TArray & B,
223  const TArray & C
224  )
225  {
226  normal2D(A, B, m_N);
227  prec_type sAB = dot(P - A, m_N);
228  prec_type s = dot(C - A, m_N);
229  if (!fuzzy::same_sign(s, sAB)) return false;
230  normal2D(B, C, m_N);
231  prec_type sBC = dot(P - B, m_N);
232  if (!fuzzy::same_sign(sBC, sAB)) return false;
233  normal2D(C, A, m_N);
234  prec_type sCA = dot(P - C, m_N);
235  if (!fuzzy::same_sign(sCA, sAB)) return false;
236  return true;
237  }
238  private: // data, internals
240  };
241 
244  template < typename TPrec, typename TPoint >
246  {
247  bool
248  operator()
249  (
250  const TPoint & p,
251  const TPoint & a,
252  const TPoint & b,
253  const TPoint & c
254  )
255  {
256  TPrec d = 0.0;
257  Matrix3<TPrec> m;
258 
259  m(0,0) = a[0];
260  m(1,0) = a[1];
261  m(2,0) = norm2(a, prec<TPrec>());
262  m(0,1) = b[0];
263  m(1,1) = b[1];
264  m(2,1) = norm2(b, prec<TPrec>());
265  m(0,2) = c[0];
266  m(1,2) = c[1];
267  m(2,2) = norm2(c, prec<TPrec>());
268  d += det(m);
269 
270  m(0,2) = p[0];
271  m(1,2) = p[1];
272  m(2,2) = norm2(p, prec<TPrec>());
273  d -= det(m);
274 
275  m(0,1) = c[0];
276  m(1,1) = c[1];
277  m(2,1) = norm2(c, prec<TPrec>());
278  d += det(m);
279 
280  m(0,0) = b[0];
281  m(1,0) = b[1];
282  m(2,0) = norm2(b, prec<TPrec>());
283  d -= det(m);
284 
285  return d > 0;
286  }
287  };
288 
290  template < typename TPrec, typename TPoint >
292  {
293  bool
294  operator()
295  (
296  const TPoint & p,
297  const TPoint & a,
298  const TPoint & b,
299  const TPoint & c
300  )
301  {
302  // ensure a, b, c lie counter-clockwise
303  if ((b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0]) >= 0)
304  {
306  //return is_in_circumcircle_counterclockwise<TPrec>(p,a,b,c);
307  }
308  else
309  {
311  //return is_in_circumcircle_counterclockwise<TPrec>(p,a,c,b);
312  }
313  }
314  };
315  };
316 
317  //---------------------------------------------------------------------------
318 
319  //-----------//
320  // Project //
321  //-----------//
322 
324  struct Project
325  {
326 
327  template < typename TArray, typename TPrecArray >
329  {
330  public: // typedefs
331  typedef typename TPrecArray::value_type prec_type;
332  //typedef typename TArray::value_type prec_type;
333  //typedef typename change_precision<TArray, TPrec>::type TPrecArray;
334  //private: // typedefs
335  //typedef numeric_array<prec_type,2> Array2D;
336  public: // functions
337  void operator()
338  (
339  const TArray & P,
340  const TArray & A, const TArray & B,
341  TPrecArray & output
342  )
343  {
344  using namespace til::expr;
345  detail::loop_xxx(*_1 = cast<prec_type>(*_2 - *_3), m_N.begin(), m_N.end(), B.begin(), A.begin());
346  //m_N = B - A;
347  m_N *= 1/norm<prec_type>(m_N);
348  prec_type lambda = dot(P-A, m_N, prec<typename TPrecArray::value_type>());
349  detail::loop_xxx(*_1 = *_2 + *_3 * lambda, output.begin(), output.end(), A.begin(), m_N.begin());
350  //output = A + m_N * dot(P-A, m_N, prec<typename TPrecArray::value_type>());
351  }
352  private:
353  TPrecArray m_N;
354  };
355 
356  template < typename TArray, typename TPrecArray >
358  {
359  public: // typedefs
360  typedef typename TPrecArray::value_type prec_type;
361  public: // functions
362  void operator()
363  (
364  const TArray & P,
365  const TArray & A, const TArray & B,
366  TPrecArray & output
367  )
368  {
369  using namespace til::expr;
370  detail::loop_xxx(*_1 = cast<prec_type>(*_2 - *_3), m_N.begin(), m_N.end(), B.begin(), A.begin());
371  prec_type lambda = dot(P-A, m_N, prec<typename TPrecArray::value_type>());
372  if (lambda < 0)
373  {
374  std::copy(A.begin(), A.end(), output.begin());
375  }
376  else if (lambda > norm2(m_N, prec<typename TPrecArray::value_type>()))
377  {
378  std::copy(B.begin(), B.end(), output.begin());
379  }
380  else
381  {
382  detail::loop_xxx(*_1 = *_2 + *_3 * lambda, output.begin(), output.end(), A.begin(), m_N.begin());
383  }
384  }
385  private: // data
386  TPrecArray m_N;
387  };
388 
392  template < typename TArray, typename TOutputArray >
394  {
395  public: // typedefs
396  typedef typename TOutputArray::value_type prec_type;
397  //typedef typename TArray::value_type prec_type;
398  //typedef typename change_precision<TArray, TPrec>::type TPrecArray;
399  private: // typedefs
401  public: // functions
402  void operator()
403  (
404  const TArray & P,
405  const TArray & A, const TArray & B, const TArray & C,
406  TOutputArray & output
407  )
408  {
409  // Compute triangle normal
410  if (!triangle_normal(A, B, C, m_N))
411  {
412  // If triangle is degenerate, compute projection on a segment.
413  TArray X, Y;
414  triangle2segment(A, B, C, X, Y);
415  PointOnSegment3D<TArray, TOutputArray>()(P, X, Y, output);
416  // TODO: projection on a point should follow...
417  return;
418  }
419  output += dot(A-P, m_N, prec<typename TOutputArray::value_type>())*m_N;
420  // project everybody on the closest canonical 2D plane
421  std::size_t i = min_index(std::abs(m_N[0]),std::abs(m_N[1]),std::abs(m_N[2]));
422  std::size_t j = (i+1)%3;
423  std::size_t k = (i+2)%3;
424  Array2D a; a[0] = A[j]; a[1] = A[k];
425  Array2D b; b[0] = B[j]; b[1] = B[k];
426  Array2D c; c[0] = C[j]; c[1] = C[k];
427  Array2D p; p[0] = p[j]; p[1] = p[k];
428 
429  Array2D n;
430  normal2D(a, b, n);
431  prec_type sAB = dot(p - a, n);
432  prec_type s = dot(c - a, n);
433  normal2D(b, c, n);
434  prec_type sBC = dot(p - b, n);
435  normal2D(c, a, n);
436  prec_type sCA = dot(p - c, n);
437 
438  if (!fuzzy::same_sign(s, sAB))
439  {
440  if (!fuzzy::same_sign(s, sBC))
441  {
442  std::copy(B.begin(), B.end(), output.begin());
443  //output = B;
444  }
445  else if (!fuzzy::same_sign(s, sCA))
446  {
447  std::copy(A.begin(), A.end(), output.begin());
448  //output = A;
449  }
450  else
451  {
452  m_projline(P, A, B, output);
453  }
454  }
455  else if (!fuzzy::same_sign(s, sBC))
456  {
457  if (!fuzzy::same_sign(s, sCA))
458  {
459  std::copy(C.begin(), C.end(), output.begin());
460  //output = C;
461  }
462  else
463  {
464  m_projline(P, B, C, output);
465  }
466  }
467  else if (!fuzzy::same_sign(s, sCA))
468  {
469  m_projline(P, C, A, output);
470  }
471  }
472 
473  private: // data, internals
474  TOutputArray m_N;
476  };
477  };
478 
479  //---------------------------------------------------------------------------
480 
481  //-------------------//
482  // AreIntersecting //
483  //-------------------//
484 
487  {
489  template < typename TArray >
491  {
492  public: // typedefs
493  typedef typename TArray::value_type prec_type;
494  public: // functions
495  bool operator()
496  (
497  const TArray & A1, const TArray & B1,
498  const TArray & A2, const TArray & B2
499  )
500  {
501  normal2D(A1, B1, m_N);
502  if (fuzzy::same_sign(dot(A2 - A1, m_N), dot(B2 - A1, m_N)))
503  {
504  return false;
505  }
506  normal2D(A2, B2, m_N);
507  if (fuzzy::same_sign(dot(A1 - A2, m_N), dot(B1 - A2, m_N)))
508  {
509  return false;
510  }
511  return true;
512  }
513  private: // data, internals
515  };
516 
518  template < typename TArray >
520  {
521  public: // functions
522  bool operator()
523  (
524  const TArray & A1, const TArray & B1, const TArray & C1,
525  const TArray & A2, const TArray & B2, const TArray & C2
526  )
527  {
528  // Check if edges are intersecting
529  if (m_interseg(A1,B1,A2,B2)) return true;
530  if (m_interseg(A1,C1,A2,B2)) return true;
531  if (m_interseg(B1,C1,A2,B2)) return true;
532 
533  if (m_interseg(A1,B1,A2,C2)) return true;
534  if (m_interseg(A1,C1,A2,C2)) return true;
535  if (m_interseg(B1,C1,A2,C2)) return true;
536 
537  if (m_interseg(A1,B1,B2,C2)) return true;
538  if (m_interseg(A1,C1,B2,C2)) return true;
539  if (m_interseg(B1,C1,B2,C2)) return true;
540 
541  // Check if one triangle is completely included into the other
542  if (m_pointInTriangle(A1, A2, B2, C2)) return true;
543  if (m_pointInTriangle(A2, A1, B1, C1)) return true;
544 
545  return false;
546  }
547 
548  private: // data, internals
549  // NB: these are put as private data, so that the user can avoid frequent reallocation of their own internals.
551  IsIncludedIn::PointInTriangle2D<TArray> m_pointInTriangle;
552  };
553 
554 
559  template < typename TArray >
561  {
562  public: // typedefs
563 
564  typedef typename TArray::value_type prec_type;
566  //typedef TPrec prec_type;
567  //typedef typename change_precision<TArray, TPrec>::type TPrecArray;
568 
569  public: // functions
570 
572  bool operator()
573  (
574  const TArray & A1, const TArray & B1, const TArray & C1,
575  const TArray & A2, const TArray & B2, const TArray & C2
576  )
577  {
578  const prec_type EPSILON = 128 * std::numeric_limits<prec_type>::epsilon();
579 
580  triangle_normal(A1, B1, C1, m_N1);
581  m_N1 *= 1/norm<prec_type>(m_N1);
582  // Checking if the vertices of the second triangle are on one side of the first
583  prec_type dA2 = dot(m_N1, A2-A1);
584  prec_type dB2 = dot(m_N1, B2-A1);
585  prec_type dC2 = dot(m_N1, C2-A1);
586  bool sAB2 = fuzzy::same_sign(dA2, dB2);
587  bool sAC2 = fuzzy::same_sign(dA2, dC2);
588  bool sBC2 = fuzzy::same_sign(dB2, dC2);
589  // NB: one can be surprised to have three tests instead of two. However, it improves robustness, esp.
590  // when one of the distance is exactly zero.
591  if (sAB2 && sAC2 && sBC2) return false;
592 
593  triangle_normal(A2, B2, C2, m_N2);
594  m_N2 *= 1/norm<prec_type>(m_N2);
595  // Checking if the vertices of the first triangle are on one side of the second
596  prec_type dA1 = dot(m_N2, A1-A2);
597  prec_type dB1 = dot(m_N2, B1-A2);
598  prec_type dC1 = dot(m_N2, C1-A2);
599  bool sAB1 = fuzzy::same_sign(dA1, dB1);
600  bool sAC1 = fuzzy::same_sign(dA1, dC1);
601  bool sBC1 = fuzzy::same_sign(dB1, dC1);
602  if (sAB1 && sAC1 && sBC1) return false;
603 
604  m_D = cross<prec_type>(m_N1, m_N2);
605  prec_type D0 = std::abs(m_D[0]);
606  prec_type D1 = std::abs(m_D[1]);
607  prec_type D2 = std::abs(m_D[2]);
608  if (max(D0, D1, D2) < EPSILON)
609  { // coplanar, 2D case
610 
611  // Project points on a 2D plane
612  // Instead of projecting on the plane with normal D, we project on a canonical plane
613  // maximizing their areas -- this avoid many multiplications.
614  std::size_t i = min_index(D0,D1,D2);
615  std::size_t j = (i+1)%3;
616  std::size_t k = (i+2)%3;
617 
618  Array2D a1; a1[0] = A1[j]; a1[1] = A1[k];
619  Array2D b1; b1[0] = B1[j]; b1[1] = B1[k];
620  Array2D c1; c1[0] = C1[j]; c1[1] = C1[k];
621 
622  Array2D a2; a2[0] = A2[j]; a2[1] = A2[k];
623  Array2D b2; b2[0] = B2[j]; b2[1] = B2[k];
624  Array2D c2; c2[0] = C2[j]; c2[1] = C2[k];
625 
626  return m_intersectTriangle2D(a1,b1,c1,a2,b2,c2);
627  }
628  else
629  {
630  dA1 = std::abs(dA1);
631  dB1 = std::abs(dB1);
632  dC1 = std::abs(dC1);
633  dA2 = std::abs(dA2);
634  dB2 = std::abs(dB2);
635  dC2 = std::abs(dC2);
636 
637  /*
638  // NB: numerically, this doesn't seem to work, even though moeller pretends it does
639  std::size_t i = max_index(D0, D1, D2);
640  prec_type a1 = A1[i];
641  prec_type b1 = B1[i];
642  prec_type c1 = C1[i];
643  prec_type a2 = A2[i];
644  prec_type b2 = B2[i];
645  prec_type c2 = C2[i];
646  */
647 
648  prec_type a1 = dot<prec_type>(A1, m_D);
649  prec_type b1 = dot<prec_type>(B1, m_D);
650  prec_type c1 = dot<prec_type>(C1, m_D);
651  prec_type a2 = dot<prec_type>(A2, m_D);
652  prec_type b2 = dot<prec_type>(B2, m_D);
653  prec_type c2 = dot<prec_type>(C2, m_D);
654 
655 
656  prec_type emin, emax;
657  if (!sAB1 && !sAC1)
658  {
659  emin = line_coord(a1, b1, dA1, dB1);
660  emax = line_coord(a1, c1, dA1, dC1);
661  }
662  else if (!sAB1)
663  {
664  emin = line_coord(b1, a1, dB1, dA1);
665  emax = line_coord(b1, c1, dB1, dC1);
666  }
667  else
668  {
669  emin = line_coord(c1, a1, dC1, dA1);
670  emax = line_coord(c1, b1, dC1, dB1);
671  }
672  if (emin > emax) std::swap(emin, emax);
673 
674 
675  prec_type fmin, fmax;
676  if (!sAB1 && !sAC1)
677  {
678  fmin = line_coord(a2, b2, dA2, dB2);
679  fmax = line_coord(a2, c2, dA2, dC2);
680  }
681  else if (!sAB1)
682  {
683  fmin = line_coord(b2, a2, dB2, dA2);
684  fmax = line_coord(b2, c2, dB2, dC2);
685  }
686  else
687  {
688  fmin = line_coord(c2, a2, dC2, dA2);
689  fmax = line_coord(c2, b2, dC2, dB2);
690  }
691  if (fmin > fmax) std::swap(fmin, fmax);
692 
693  if (fmin > emax || fmax < emin) return false;
694 
695  /*
696  std::cout << A1 << " " << B1 << " " << C1 << std::endl;
697  std::cout << A2 << " " << B2 << " " << C2 << std::endl;
698 
699  std::cout << m_N1 << std::endl;
700  std::cout << A2-A1 << " " << B2-A1 << " " << C2-A1 << std::endl;
701  std::cout << dA2 << " " << dB2 << " " << dC2 << std::endl;
702  //std::cout << sAB2 << " " << sAC2 << std::endl;
703  std::cout << m_N2 << std::endl;
704  std::cout << A1-A2 << " " << B1-A2 << " " << C1-A2 << std::endl;
705  std::cout << dA1 << " " << dB1 << " " << dC1 << std::endl;
706 
707  std::cout << m_D << std::endl;
708  std::cout << D0 << " " << D1 << " " << D2 << std::endl;
709  std::cout << i << std::endl;
710 
711  std::cout << emin << " " << emax << " " << fmin << " " << fmax << std::endl;
712  */
713 
714  return true;
715  }
716  }
717 
718  private: // functions
719 
720  prec_type line_coord(prec_type a, prec_type b, prec_type da, prec_type db)
721  { return a + (b-a) * da / (da + db); }
722 
723 
724  private: // data, internals
725 
726  AreIntersecting::Triangles2D<Array2D> m_intersectTriangle2D;
727  /*
728  TPrecArray m_N1;
729  TPrecArray m_N2;
730  TPrecArray m_D;
731  */
733  TArray m_N1;
734  TArray m_N2;
735  TArray m_D;
736  //*/
737  };
738  };
739 
740 
741  //---------------------------------------------------------------------------
742 
743  //--------------------//
744  // Helper functions //
745  //--------------------//
746 
748  template < typename TPrec, typename TPoint >
749  inline bool is_in_circumcircle
750  (
751  const TPoint & p,
752  const TPoint & a,
753  const TPoint & b,
754  const TPoint & c
755  )
756  {
758  }
759 
760 
761 }} // namespace til::geo
762 
763 // package include
764 #include "geometrics.tpp"
765 
766 
767 #endif /*GEOMETRICS_H_*/
namespace for template expressions.
Project a point onto a 3D triangle.
Definition: geometrics.h:393
A namespace structure collecting geometrical projection algorithms.
Definition: geometrics.h:324
const TExpr< expr::ThirdArgument > _3
Placeholder for the third argument.
Definition: TExpr.h:209
TPrec norm2(const numeric_array< T, D > &a, prec< TPrec >)
Return the squared euclidean norm of a.
T law_of_cosines(T a, T b, T c)
Returns the cosine of angle A given the lengths of the triangle edges.
Checks if a 2D point lies within the circumcircle of a 2D triangle.
Definition: geometrics.h:291
TResArray::value_type prec_type
Definition: geometrics.h:154
TPrec dot(const numeric_array< T1, D > &a1, const numeric_array< T2, D > &a2, prec< TPrec >)
Return the dot product of two vectors.
INLINE double norm(const T &a, const T &b)
< Euclidean norm of 2D vector (a, b)
TArray::value_type prec_type
Definition: geometrics.h:98
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
bool triangle_normal(const TArray &A, const TArray &B, const TArray &C, TResArray &result)
Compute the normal of a triangle.
T law_of_tangents(T a, T b, T c, T area)
Returns the tangent of angle A given the area and the lengths of the edges of the triangle...
Approximate an ill-conditionned triangle by a segment.
Definition: geometrics.h:95
boost::logic::tribool same_sign(T x, T y, T delta=128 *std::numeric_limits< T >::epsilon())
Returns true iff both arguments have same sign, allowing some degree of imprecision.
void spherical2cartesian(T theta, T phi, T rho, T &x, T &y, T &z)
Converts spherical coordinates into cartesian coordinates.
Compute the normal of a triangle.
Definition: geometrics.h:145
Check whether two 2D triangles are intersecting or not.
Definition: geometrics.h:519
A namespace structure collecting geometrical object intersection algorithms.
Definition: geometrics.h:486
This exeception is thrown whenever a reliable computation of the triangle normal cannot be achieved...
Definition: geometrics.h:150
numeric_array< T, D > abs(const numeric_array< T, D > &a)
Absolute value, element-wise.
TPrecArray::value_type prec_type
Definition: geometrics.h:331
bool triangle2segment(const TArray &A, const TArray &B, const TArray &C, TArray &X, TArray &Y)
Definition: geometrics.h:130
Checks if a 2D point lies within a 2D triangle.
Definition: geometrics.h:213
bool is_in_circumcircle(const TPoint &p, const TPoint &a, const TPoint &b, const TPoint &c)
Check whether a point lies within the circumcircle of a given triangle.
Definition: geometrics.h:750
A namespace structure collecting geometrical object inclusion algorithms.
Definition: geometrics.h:209
TImage::value_type max(const TImage &im)
Returns the maximum intensity of the input image.
T angle(T x, T y, T norm)
Returns the angle between (x,y) and the x-axis, with the norm of (x,y) provided.
void copy(const TImage &in, TImage &out)
Copy one image to another.
Definition: imageTools.h:133
A mathematical matrix.
Definition: Matrix3.h:90
numeric_array< prec_type, 2 > Array2D
Definition: geometrics.h:565
const TExpr< expr::SecondArgument > _2
Placeholder for the second argument.
Definition: TExpr.h:207
const TExpr< expr::FirstArgument > _1
Placeholder for the first argument.
Definition: TExpr.h:205
void cartesian2spherical(T x, T y, T z, T &theta, T &phi, T &rho)
Converts cartesian coordinates into spherical coordinates.
Check whether two 2D segments are intersecting or not.
Definition: geometrics.h:490
Checks if a 2D point lies within the circumcircle of a triangle, whose vertices are given in a counte...
Definition: geometrics.h:245
void loop_xxx(expr::TExpr< Expr > expr, TIterator1 start1, const TIterator1 end1, TIterator2 start2, TIterator3 start3)
Definition: TExpr.h:410
T herons_formula(T a, T b, T c)
Heron&#39;s formula.
T det(const Matrix3< T > &m)
Definition: matrix3Tools.h:79
Check whether two triangles are intersecting or not.
Definition: geometrics.h:560
TOutputArray::value_type prec_type
Definition: geometrics.h:396
A dummy class used to pass a precision type for computations to some functions.
std::size_t min_index(T x0, T x1, T x2)
Returns i0, where X_i0 is the smallest of all Xi&#39;s.
TPrecArray::value_type prec_type
Definition: geometrics.h:360