triangleI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "IOstreams.H"
27 #include "pointHit.H"
28 #include "mathematicalConstants.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Point, class PointRef>
34 (
35  const Point& a,
36  const Point& b,
37  const Point& c
38 )
39 :
40  a_(a),
41  b_(b),
42  c_(c)
43 {}
44 
45 
46 template<class Point, class PointRef>
48 (
49  const UList<Point>& points,
50  const FixedList<label, 3>& indices
51 )
52 :
53  a_(points[indices[0]]),
54  b_(points[indices[1]]),
55  c_(points[indices[2]])
56 {}
57 
58 
59 
60 template<class Point, class PointRef>
62 {
63  is >> *this;
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
69 template<class Point, class PointRef>
70 inline const Point& Foam::triangle<Point, PointRef>::a() const
71 {
72  return a_;
73 }
74 
75 template<class Point, class PointRef>
76 inline const Point& Foam::triangle<Point, PointRef>::b() const
77 {
78  return b_;
79 }
80 
81 template<class Point, class PointRef>
82 inline const Point& Foam::triangle<Point, PointRef>::c() const
83 {
84  return c_;
85 }
86 
87 
88 template<class Point, class PointRef>
90 {
91  return (1.0/3.0)*(a_ + b_ + c_);
92 }
93 
94 
95 template<class Point, class PointRef>
97 {
98  return 0.5*((b_ - a_)^(c_ - a_));
99 }
100 
101 
102 template<class Point, class PointRef>
103 inline Foam::scalar Foam::triangle<Point, PointRef>::mag() const
104 {
105  return Foam::mag(area());
106 }
107 
108 
109 template<class Point, class PointRef>
111 {
112  const vector a = area();
113  const scalar maga = Foam::mag(a);
114  return maga > 0 ? a/maga : Zero;
115 }
116 
117 
118 template<class Point, class PointRef>
120 {
121  scalar d1 = (c_ - a_) & (b_ - a_);
122  scalar d2 = -(c_ - b_) & (b_ - a_);
123  scalar d3 = (c_ - a_) & (c_ - b_);
124 
125  scalar c1 = d2*d3;
126  scalar c2 = d3*d1;
127  scalar c3 = d1*d2;
128 
129  scalar c = c1 + c2 + c3;
130 
131  if (Foam::mag(c) < rootVSmall)
132  {
133  // Degenerate triangle, returning centre instead of circumCentre.
134 
135  return centre();
136  }
137 
138  return
139  (
140  ((c2 + c3)*a_ + (c3 + c1)*b_ + (c1 + c2)*c_)/(2*c)
141  );
142 }
143 
144 
145 template<class Point, class PointRef>
147 {
148  scalar d1 = (c_ - a_) & (b_ - a_);
149  scalar d2 = -(c_ - b_) & (b_ - a_);
150  scalar d3 = (c_ - a_) & (c_ - b_);
151 
152  scalar denom = d2*d3 + d3*d1 + d1*d2;
153 
154  if (Foam::mag(denom) < vSmall)
155  {
156  // Degenerate triangle, returning great for circumRadius.
157 
158  return great;
159  }
160  else
161  {
162  scalar a = (d1 + d2)*(d2 + d3)*(d3 + d1) / denom;
163 
164  return 0.5*Foam::sqrt(min(great, max(0, a)));
165  }
166 }
167 
168 
169 template<class Point, class PointRef>
170 inline Foam::scalar Foam::triangle<Point, PointRef>::quality() const
171 {
172  scalar c = circumRadius();
173 
174  if (c < rootVSmall)
175  {
176  // zero circumRadius, something has gone wrong.
177  return small;
178  }
179 
180  return mag()/(Foam::sqr(c)*3.0*sqrt(3.0)/4.0);
181 }
182 
183 
184 template<class Point, class PointRef>
186 (
187  const triangle& t
188 ) const
189 {
190  return (1.0/12.0)*
191  (
192  ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
193  + ((t.b_ - b_) & ((c_ - b_)^(t.a_ - b_)))
194  + ((c_ - t.c_) & ((t.b_ - t.c_)^(t.a_ - t.c_)))
195 
196  + ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
197  + ((b_ - t.b_) & ((t.a_ - t.b_)^(t.c_ - t.b_)))
198  + ((c_ - t.c_) & ((b_ - t.c_)^(t.a_ - t.c_)))
199  );
200 }
201 
202 
203 template<class Point, class PointRef>
205 (
206  PointRef refPt,
207  scalar density
208 ) const
209 {
210  Point aRel = a_ - refPt;
211  Point bRel = b_ - refPt;
212  Point cRel = c_ - refPt;
213 
214  tensor V
215  (
216  aRel.x(), aRel.y(), aRel.z(),
217  bRel.x(), bRel.y(), bRel.z(),
218  cRel.x(), cRel.y(), cRel.z()
219  );
220 
221  scalar a = Foam::mag((b_ - a_)^(c_ - a_));
222 
223  tensor S = 1/24.0*(tensor::one + I);
224 
225  return
226  (
227  a*I/24.0*
228  (
229  (aRel & aRel)
230  + (bRel & bRel)
231  + (cRel & cRel)
232  + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
233  )
234  - a*(V.T() & S & V)
235  )
236  *density;
237 }
238 
239 
240 template<class Point, class PointRef>
242 {
243  return barycentricToPoint(barycentric2D01(rndGen));
244 }
245 
246 
247 template<class Point, class PointRef>
249 (
250  const barycentric2D& bary
251 ) const
252 {
253  return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
254 }
255 
256 
257 template<class Point, class PointRef>
259 (
260  const point& pt
261 ) const
262 {
263  barycentric2D bary;
264  pointToBarycentric(pt, bary);
265  return bary;
266 }
267 
268 
269 template<class Point, class PointRef>
271 (
272  const point& pt,
273  barycentric2D& bary
274 ) const
275 {
276  // Reference:
277  // Real-time collision detection, Christer Ericson, 2005, p47-48
278 
279  vector v0 = b_ - a_;
280  vector v1 = c_ - a_;
281  vector v2 = pt - a_;
282 
283  scalar d00 = v0 & v0;
284  scalar d01 = v0 & v1;
285  scalar d11 = v1 & v1;
286  scalar d20 = v2 & v0;
287  scalar d21 = v2 & v1;
288 
289  scalar denom = d00*d11 - d01*d01;
290 
291  if (Foam::mag(denom) < small)
292  {
293  // Degenerate triangle, returning 1/3 barycentric coordinates.
294 
295  bary = barycentric2D(1.0/3.0, 1.0/3.0, 1.0/3.0);
296 
297  return denom;
298  }
299 
300  bary[1] = (d11*d20 - d01*d21)/denom;
301  bary[2] = (d00*d21 - d01*d20)/denom;
302  bary[0] = 1.0 - bary[1] - bary[2];
303 
304  return denom;
305 }
306 
307 
308 template<class Point, class PointRef>
310 (
311  const point& p,
312  const vector& q,
313  const intersection::algorithm alg,
314  const intersection::direction dir
315 ) const
316 {
317  // Express triangle in terms of baseVertex (point a_) and
318  // two edge vectors
319  const vector E0 = b_ - a_;
320  const vector E1 = c_ - a_;
321 
322  // Initialise intersection to miss.
323  pointHit inter(p);
324 
325  vector n(0.5*(E0 ^ E1));
326  const scalar magArea = Foam::mag(n);
327 
328  if (magArea < vSmall)
329  {
330  // Ineligible miss.
331  inter.setMiss(false);
332 
333  // The miss point is the nearest point on the triangle. Take any one.
334  inter.setPoint(a_);
335 
336  // The distance to the miss is the distance between the
337  // original point and plane of intersection. No normal so use
338  // distance from p to a_
339  inter.setDistance(Foam::mag(a_ - p));
340 
341  return inter;
342  }
343 
344  const vector q1 = q/Foam::mag(q);
345 
346  if (dir == intersection::direction::contactSphere)
347  {
348  n /= magArea;
349 
350  return ray(p, q1 - n, alg, intersection::direction::vector);
351  }
352 
353  // Intersection point with triangle plane
354  point pInter;
355 
356  // Is intersection point inside triangle
357  bool hit;
358  {
359  // Reuse the fast ray intersection routine below in algorithm::fullRay
360  // mode since the original intersection routine has rounding problems.
361  pointHit fastInter = intersection
362  (
363  p,
364  q1,
365  intersection::algorithm::fullRay
366  );
367  hit = fastInter.hit();
368 
369  if (hit)
370  {
371  pInter = fastInter.rawPoint();
372  }
373  else
374  {
375  // Calculate intersection of ray with triangle plane
376  vector v = a_ - p;
377  pInter = p + (q1&v)*q1;
378  }
379  }
380 
381  // Distance to intersection point
382  const scalar dist = q1 & (pInter - p);
383 
384  const scalar planarPointTol =
385  Foam::min
386  (
387  Foam::min
388  (
389  Foam::mag(E0),
390  Foam::mag(E1)
391  ),
392  Foam::mag(c_ - b_)
393  )*intersection::planarTol();
394 
395  bool eligible =
396  alg == intersection::algorithm::fullRay
397  || (alg == intersection::algorithm::halfRay && dist > -planarPointTol)
398  || (
399  alg == intersection::algorithm::visible
400  && ((q1 & area()) < -vSmall)
401  );
402 
403  if (hit && eligible)
404  {
405  // Hit. Set distance to intersection.
406  inter.setHit();
407  inter.setPoint(pInter);
408  inter.setDistance(dist);
409  }
410  else
411  {
412  // Miss or ineligible hit.
413  inter.setMiss(eligible);
414 
415  // The miss point is the nearest point on the triangle
416  inter.setPoint(nearestPoint(p).rawPoint());
417 
418  // The distance to the miss is the distance between the
419  // original point and plane of intersection
420  inter.setDistance(Foam::mag(pInter - p));
421  }
422 
423  return inter;
424 }
425 
426 
427 // From "Fast, Minimum Storage Ray/Triangle Intersection"
428 // Moeller/Trumbore.
429 template<class Point, class PointRef>
431 (
432  const point& orig,
433  const vector& dir,
434  const intersection::algorithm alg,
435  const scalar tol
436 ) const
437 {
438  const vector edge1 = b_ - a_;
439  const vector edge2 = c_ - a_;
440 
441  // Begin calculating determinant - also used to calculate U parameter
442  const vector pVec = dir ^ edge2;
443 
444  // Ff determinant is near zero, ray lies in plane of triangle
445  const scalar det = edge1 & pVec;
446 
447  // Initialise to miss
448  pointHit intersection(false, Zero, great, false);
449 
450  if (alg == intersection::algorithm::visible)
451  {
452  // Culling branch
453  if (det < rootVSmall)
454  {
455  // Ray on wrong side of triangle. Return miss
456  return intersection;
457  }
458  }
459  else if
460  (
461  alg == intersection::algorithm::halfRay
462  || alg == intersection::algorithm::fullRay
463  )
464  {
465  // Non-culling branch
466  if (det > -rootVSmall && det < rootVSmall)
467  {
468  // Ray parallel to triangle. Return miss
469  return intersection;
470  }
471  }
472 
473  const scalar inv_det = 1.0 / det;
474 
475  // Calculate distance from a_ to ray origin
476  const vector tVec = orig-a_;
477 
478  // Calculate U parameter and test bounds
479  const scalar u = (tVec & pVec)*inv_det;
480 
481  if (u < -tol || u > 1.0+tol)
482  {
483  // return miss
484  return intersection;
485  }
486 
487  // Prepare to test V parameter
488  const vector qVec = tVec ^ edge1;
489 
490  // Calculate V parameter and test bounds
491  const scalar v = (dir & qVec) * inv_det;
492 
493  if (v < -tol || u + v > 1.0+tol)
494  {
495  // return miss
496  return intersection;
497  }
498 
499  // Calculate t, scale parameters, ray intersects triangle
500  const scalar t = (edge2 & qVec) * inv_det;
501 
502  if (alg == intersection::algorithm::halfRay && t < -tol)
503  {
504  // Wrong side of orig. Return miss
505  return intersection;
506  }
507 
508  intersection.setHit();
509  intersection.setPoint(a_ + u*edge1 + v*edge2);
510  intersection.setDistance(t);
511 
512  return intersection;
513 }
514 
515 
516 template<class Point, class PointRef>
518 (
519  const point& p,
520  label& nearType,
521  label& nearLabel
522 ) const
523 {
524  // Adapted from:
525  // Real-time collision detection, Christer Ericson, 2005, p136-142
526 
527  // Check if P in vertex region outside A
528  vector ab = b_ - a_;
529  vector ac = c_ - a_;
530  vector ap = p - a_;
531 
532  scalar d1 = ab & ap;
533  scalar d2 = ac & ap;
534 
535  if (d1 <= 0.0 && d2 <= 0.0)
536  {
537  // barycentric coordinates (1, 0, 0)
538 
539  nearType = POINT;
540  nearLabel = 0;
541  return pointHit(false, a_, Foam::mag(a_ - p), true);
542  }
543 
544  // Check if P in vertex region outside B
545  vector bp = p - b_;
546  scalar d3 = ab & bp;
547  scalar d4 = ac & bp;
548 
549  if (d3 >= 0.0 && d4 <= d3)
550  {
551  // barycentric coordinates (0, 1, 0)
552 
553  nearType = POINT;
554  nearLabel = 1;
555  return pointHit(false, b_, Foam::mag(b_ - p), true);
556  }
557 
558  // Check if P in edge region of AB, if so return projection of P onto AB
559  scalar vc = d1*d4 - d3*d2;
560 
561  if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
562  {
563  if ((d1 - d3) < rootVSmall)
564  {
565  // Degenerate triangle, for d1 = d3, a_ and b_ are likely coincident
566  nearType = POINT;
567  nearLabel = 0;
568  return pointHit(false, a_, Foam::mag(a_ - p), true);
569  }
570 
571  // barycentric coordinates (1-v, v, 0)
572  scalar v = d1/(d1 - d3);
573 
574  point nearPt = a_ + v*ab;
575  nearType = EDGE;
576  nearLabel = 0;
577  return pointHit(false, nearPt, Foam::mag(nearPt - p), true);
578  }
579 
580  // Check if P in vertex region outside C
581  vector cp = p - c_;
582  scalar d5 = ab & cp;
583  scalar d6 = ac & cp;
584 
585  if (d6 >= 0.0 && d5 <= d6)
586  {
587  // barycentric coordinates (0, 0, 1)
588 
589  nearType = POINT;
590  nearLabel = 2;
591  return pointHit(false, c_, Foam::mag(c_ - p), true);
592  }
593 
594  // Check if P in edge region of AC, if so return projection of P onto AC
595  scalar vb = d5*d2 - d1*d6;
596 
597  if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
598  {
599  if ((d2 - d6) < rootVSmall)
600  {
601  // Degenerate triangle, for d2 = d6, a_ and c_ are likely coincident
602  nearType = POINT;
603  nearLabel = 0;
604  return pointHit(false, a_, Foam::mag(a_ - p), true);
605  }
606 
607  // barycentric coordinates (1-w, 0, w)
608  scalar w = d2/(d2 - d6);
609 
610  point nearPt = a_ + w*ac;
611  nearType = EDGE;
612  nearLabel = 2;
613  return pointHit(false, nearPt, Foam::mag(nearPt - p), true);
614  }
615 
616  // Check if P in edge region of BC, if so return projection of P onto BC
617  scalar va = d3*d6 - d5*d4;
618 
619  if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
620  {
621  if (((d4 - d3) + (d5 - d6)) < rootVSmall)
622  {
623  // Degenerate triangle, for (d4 - d3) = (d6 - d5), b_ and c_ are
624  // likely coincident
625  nearType = POINT;
626  nearLabel = 1;
627  return pointHit(false, b_, Foam::mag(b_ - p), true);
628  }
629 
630  // barycentric coordinates (0, 1-w, w)
631  scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
632 
633  point nearPt = b_ + w*(c_ - b_);
634  nearType = EDGE;
635  nearLabel = 1;
636  return pointHit(false, nearPt, Foam::mag(nearPt - p), true);
637  }
638 
639  // P inside face region. Compute Q through its barycentric
640  // coordinates (u, v, w)
641 
642  if ((va + vb + vc) < rootVSmall)
643  {
644  // Degenerate triangle, return the centre because no edge or points are
645  // closest
646  point nearPt = centre();
647  nearType = NONE,
648  nearLabel = -1;
649  return pointHit(true, nearPt, Foam::mag(nearPt - p), false);
650  }
651 
652  scalar denom = 1.0/(va + vb + vc);
653  scalar v = vb * denom;
654  scalar w = vc * denom;
655 
656  // = u*a + v*b + w*c, u = va*denom = 1.0 - v - w
657 
658  point nearPt = a_ + ab*v + ac*w;
659  nearType = NONE,
660  nearLabel = -1;
661  return pointHit(true, nearPt, Foam::mag(nearPt - p), false);
662 }
663 
664 
665 template<class Point, class PointRef>
667 (
668  const point& p
669 ) const
670 {
671  // Dummy labels
672  label nearType = -1;
673  label nearLabel = -1;
674 
675  return nearestPointClassify(p, nearType, nearLabel);
676 }
677 
678 
679 template<class Point, class PointRef>
681 (
682  const point& p,
683  label& nearType,
684  label& nearLabel
685 ) const
686 {
687  return nearestPointClassify(p, nearType, nearLabel).hit();
688 }
689 
690 
691 template<class Point, class PointRef>
693 (
694  const linePointRef& ln,
695  pointHit& lnInfo
696 ) const
697 {
698  vector q = ln.vec();
699  pointHit triInfo
700  (
702  (
703  ln.start(),
704  q,
705  intersection::algorithm::fullRay
706  )
707  );
708 
709  if (triInfo.hit())
710  {
711  // Line hits triangle. Find point on line.
712  if (triInfo.distance() > 1)
713  {
714  // Hit beyond endpoint
715  lnInfo.setMiss(true);
716  lnInfo.setPoint(ln.end());
717  scalar dist = Foam::mag(triInfo.hitPoint()-lnInfo.missPoint());
718  lnInfo.setDistance(dist);
719  triInfo.setMiss(true);
720  triInfo.setDistance(dist);
721  }
722  else if (triInfo.distance() < 0)
723  {
724  // Hit beyond startpoint
725  lnInfo.setMiss(true);
726  lnInfo.setPoint(ln.start());
727  scalar dist = Foam::mag(triInfo.hitPoint()-lnInfo.missPoint());
728  lnInfo.setDistance(dist);
729  triInfo.setMiss(true);
730  triInfo.setDistance(dist);
731  }
732  else
733  {
734  // Hit on line
735  lnInfo.setHit();
736  lnInfo.setPoint(triInfo.hitPoint());
737  lnInfo.setDistance(0.0);
738  triInfo.setDistance(0.0);
739  }
740  }
741  else
742  {
743  // Line skips triangle. See which triangle edge it gets closest to
744 
745  point nearestEdgePoint;
746  point nearestLinePoint;
747  // label minEdgeIndex = 0;
748  scalar minDist = ln.nearestDist
749  (
750  linePointRef(a_, b_),
751  nearestLinePoint,
752  nearestEdgePoint
753  );
754 
755  {
756  point linePoint;
757  point triEdgePoint;
758  scalar dist = ln.nearestDist
759  (
760  linePointRef(b_, c_),
761  linePoint,
762  triEdgePoint
763  );
764  if (dist < minDist)
765  {
766  minDist = dist;
767  nearestEdgePoint = triEdgePoint;
768  nearestLinePoint = linePoint;
769  // minEdgeIndex = 1;
770  }
771  }
772 
773  {
774  point linePoint;
775  point triEdgePoint;
776  scalar dist = ln.nearestDist
777  (
778  linePointRef(c_, a_),
779  linePoint,
780  triEdgePoint
781  );
782  if (dist < minDist)
783  {
784  minDist = dist;
785  nearestEdgePoint = triEdgePoint;
786  nearestLinePoint = linePoint;
787  // minEdgeIndex = 2;
788  }
789  }
790 
791  lnInfo.setDistance(minDist);
792  triInfo.setDistance(minDist);
793  triInfo.setMiss(false);
794  triInfo.setPoint(nearestEdgePoint);
795 
796  // Convert point on line to pointHit
797  if (Foam::mag(nearestLinePoint-ln.start()) < small)
798  {
799  lnInfo.setMiss(true);
800  lnInfo.setPoint(ln.start());
801  }
802  else if (Foam::mag(nearestLinePoint-ln.end()) < small)
803  {
804  lnInfo.setMiss(true);
805  lnInfo.setPoint(ln.end());
806  }
807  else
808  {
809  lnInfo.setHit();
810  lnInfo.setPoint(nearestLinePoint);
811  }
812  }
813  return triInfo;
814 }
815 
816 
817 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
818 
819 template<class Point, class PointRef>
820 inline Foam::Istream& Foam::operator>>
821 (
822  Istream& is,
824 )
825 {
826  is.readBegin("triangle");
827  is >> t.a_ >> t.b_ >> t.c_;
828  is.readEnd("triangle");
829 
830  is.check("Istream& operator>>(Istream&, triangle&)");
831  return is;
832 }
833 
834 
835 template<class Point, class PointRef>
836 inline Foam::Ostream& Foam::operator<<
837 (
838  Ostream& os,
840 )
841 {
842  os << nl
843  << token::BEGIN_LIST
844  << t.a_ << token::SPACE
845  << t.b_ << token::SPACE
846  << t.c_
847  << token::END_LIST;
848 
849  return os;
850 }
851 
852 
853 // ************************************************************************* //
barycentric2D barycentric2D01(Random &rndGen)
Generate a random barycentric coordinate within the unit triangle.
Definition: barycentric2D.C:31
scalar sweptVol(const triangle &t) const
Return swept-volume.
Definition: triangleI.H:186
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
A triangle primitive used to calculate face areas and swept volumes.
Definition: triangle.H:57
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
A line primitive.
Definition: line.H:56
const Point & c() const
Return third vertex.
Definition: triangleI.H:82
Barycentric2D< scalar > barycentric2D
A scalar version of the templated Barycentric2D.
Definition: barycentric2D.H:45
barycentric2D pointToBarycentric(const point &pt) const
Calculate the barycentric coordinates from the given point.
Definition: triangleI.H:259
scalar mag() const
Return scalar magnitude.
Definition: triangleI.H:103
scalar quality() const
Return quality: Ratio of triangle and circum-circle.
Definition: triangleI.H:170
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
dimensionedScalar sqrt(const dimensionedScalar &ds)
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy, recursively if necessary, the source to the destination.
Definition: POSIX.C:753
pointHit nearestPointClassify(const point &p, label &nearType, label &nearLabel) const
Find the nearest point to p on the triangle and classify it:
Definition: triangleI.H:518
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensionedScalar det(const dimensionedSphericalTensor &dt)
scalar minDist(const List< pointIndexHit > &hitList)
const Point & missPoint() const
Return miss point.
Definition: PointHit.H:145
const dimensionedScalar c2
Second radiation constant: default SI units: [m K].
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Templated 2D Barycentric derived from VectorSpace. Has 3 components, one of which is redundant...
Definition: Barycentric2D.H:50
vector area() const
Return vector area.
Definition: triangleI.H:96
const dimensionedScalar c1
First radiation constant: default SI units: [W/m^2].
Random rndGen(label(0))
bool classify(const point &p, label &nearType, label &nearLabel) const
Classify nearest point to p in triangle plane.
Definition: triangleI.H:681
pointHit nearestPoint(const point &p) const
Return nearest point to p on triangle.
Definition: triangleI.H:667
void setHit()
Definition: PointHit.H:169
Foam::intersection.
Definition: intersection.H:49
void setDistance(const scalar d)
Definition: PointHit.H:186
line< point, const point & > linePointRef
Line using referred points.
Definition: linePointRef.H:45
static const Identity< scalar > I
Definition: Identity.H:93
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const GeometricField< Type, fvPatchField, volMesh > &)
const Point & hitPoint() const
Return hit point.
Definition: PointHit.H:126
PointRef start() const
Return first vertex.
Definition: lineI.H:60
Point centre() const
Return centre (centroid)
Definition: triangleI.H:89
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
bool hit() const
Is there a hit.
Definition: PointHit.H:120
static const zero Zero
Definition: zero.H:97
scalar circumRadius() const
Return circum-radius.
Definition: triangleI.H:146
tensor inertia(PointRef refPt=vector::zero, scalar density=1.0) const
Return the inertia tensor, with optional reference.
Definition: triangleI.H:205
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Random number generator.
Definition: Random.H:57
vector normal() const
Return unit normal.
Definition: triangleI.H:110
void setMiss(const bool eligible)
Definition: PointHit.H:175
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
triangle(const Point &a, const Point &b, const Point &c)
Construct from three points.
Definition: triangleI.H:34
const Point & rawPoint() const
Return point with no checking.
Definition: PointHit.H:158
static const char nl
Definition: Ostream.H:260
Point barycentricToPoint(const barycentric2D &bary) const
Calculate the point from the given barycentric coordinates.
Definition: triangleI.H:249
const Point & a() const
Return first vertex.
Definition: triangleI.H:70
Point vec() const
Return start-end vector.
Definition: lineI.H:87
pointHit ray(const point &p, const vector &q, const intersection::algorithm=intersection::algorithm::fullRay, const intersection::direction dir=intersection::direction::vector) const
Return point intersection with a ray.
Definition: triangleI.H:310
Point circumCentre() const
Return circum-centre.
Definition: triangleI.H:119
const Point & b() const
Return second vertex.
Definition: triangleI.H:76
PointRef end() const
Return second vertex.
Definition: lineI.H:66
Point randomPoint(Random &rndGen) const
Return a random point on the triangle from a uniform.
Definition: triangleI.H:241
dimensioned< scalar > mag(const dimensioned< Type > &)
label n
PointHit< point > pointHit
Definition: pointHit.H:41
scalar distance() const
Return distance to hit.
Definition: PointHit.H:139
volScalarField & p
pointHit intersection(const point &p, const vector &q, const intersection::algorithm alg, const scalar tol=0.0) const
Fast intersection with a ray.
Definition: triangleI.H:431
void setPoint(const Point &p)
Definition: PointHit.H:181
PointHit< Point > nearestDist(const Point &p) const
Return nearest distance to line from a given point.
Definition: lineI.H:95