72 template<
class Po
int,
class Po
intRef>
86 template<
class Po
int,
class Po
intRef>
98 template<
class Po
int,
class Po
intRef>
111 template<
class Po
int,
class Po
intRef>
120 template<
class Po
int,
class Po
intRef>
128 return (1.0/3.0)*(
p0 + p1 + p2);
132 template<
class Po
int,
class Po
intRef>
135 return (1.0/3.0)*(a_ + b_ + c_);
145 template<
class Po
int,
class Po
intRef>
153 return 0.5*((p1 -
p0)^(p2 -
p0));
157 template<
class Po
int,
class Po
intRef>
160 return 0.5*((b_ - a_)^(c_ - a_));
170 template<
class Po
int,
class Po
intRef>
179 (void)
n.normalise(ROOTVSMALL);
184 template<
class Po
int,
class Po
intRef>
197 template<
class Po
int,
class Po
intRef>
213 template<
class Po
int,
class Po
intRef>
226 template<
class Po
int,
class Po
intRef>
229 return Point(c_ - b_);
232 template<
class Po
int,
class Po
intRef>
235 return Point(a_ - c_);
238 template<
class Po
int,
class Po
intRef>
241 return Point(b_ - a_);
286 template<
class Po
int,
class Po
intRef>
293 template<
class Po
int,
class Po
intRef>
296 scalar d1 = (c_ - a_) & (b_ - a_);
297 scalar d2 = -(c_ - b_) & (b_ - a_);
298 scalar d3 = (c_ - a_) & (c_ - b_);
304 scalar
c =
c1 +
c2 + c3;
315 ((
c2 + c3)*a_ + (c3 +
c1)*b_ + (
c1 +
c2)*c_)/(2*
c)
320 template<
class Po
int,
class Po
intRef>
323 const scalar d1 = (c_ - a_) & (b_ - a_);
324 const scalar d2 = -(c_ - b_) & (b_ - a_);
325 const scalar d3 = (c_ - a_) & (c_ - b_);
327 const scalar denom = d2*d3 + d3*d1 + d1*d2;
336 const scalar a = (d1 + d2)*(d2 + d3)*(d3 + d1) / denom;
341 template<
class Po
int,
class Po
intRef>
344 scalar
c = circumRadius();
356 template<
class Po
int,
class Po
intRef>
364 ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
365 + ((t.b_ - b_) & ((c_ - b_)^(t.a_ - b_)))
366 + ((c_ - t.c_) & ((t.b_ - t.c_)^(t.a_ - t.c_)))
368 + ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
369 + ((b_ - t.b_) & ((t.a_ - t.b_)^(t.c_ - t.b_)))
370 + ((c_ - t.c_) & ((b_ - t.c_)^(t.a_ - t.c_)))
375 template<
class Po
int,
class Po
intRef>
382 Point aRel = a_ - refPt;
383 Point bRel = b_ - refPt;
384 Point cRel = c_ - refPt;
388 aRel.x(), aRel.y(), aRel.z(),
389 bRel.x(), bRel.y(), bRel.z(),
390 cRel.x(), cRel.y(), cRel.z()
393 scalar a =
Foam::mag((b_ - a_)^(c_ - a_));
395 tensor S = 1/24.0*(tensor::one +
I);
404 + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
412 template<
class Po
int,
class Po
intRef>
419 template<
class Po
int,
class Po
intRef>
425 return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
429 template<
class Po
int,
class Po
intRef>
436 pointToBarycentric(pt, bary);
441 template<
class Po
int,
class Po
intRef>
455 scalar d00 = v0 & v0;
456 scalar d01 = v0 & v1;
457 scalar d11 = v1 & v1;
458 scalar d20 = v2 & v0;
459 scalar d21 = v2 & v1;
461 scalar denom = d00*d11 - d01*d01;
472 bary[1] = (d11*d20 - d01*d21)/denom;
473 bary[2] = (d00*d21 - d01*d20)/denom;
474 bary[0] = 1.0 - bary[1] - bary[2];
480 template<
class Po
int,
class Po
intRef>
492 (((a_ - origin) & normal) < 0 ? 1 : 2)
493 | (((b_ - origin) & normal) < 0 ? 1 : 2)
494 | (((c_ - origin) & normal) < 0 ? 1 : 2)
500 template<
class Po
int,
class Po
intRef>
512 (a_[axis] < origin[axis] ? 1 : 2)
513 | (b_[axis] < origin[axis] ? 1 : 2)
514 | (c_[axis] < origin[axis] ? 1 : 2)
520 template<
class Po
int,
class Po
intRef>
573 hit = fastInter.hit();
577 pInter = fastInter.point();
583 pInter =
p + (q1&v)*q1;
588 scalar dist = q1 & (pInter -
p);
590 const scalar planarPointTol =
606 && ((q1 & areaNormal()) < -VSMALL)
635 template<
class Po
int,
class Po
intRef>
644 const vector edge1 = b_ - a_;
645 const vector edge2 = c_ - a_;
648 const vector pVec = dir ^ edge2;
651 const scalar
det = edge1 & pVec;
659 if (
det < ROOTVSMALL)
668 if (
det > -ROOTVSMALL &&
det < ROOTVSMALL)
675 const scalar inv_det = 1.0 /
det;
678 const vector tVec = orig-a_;
681 const scalar u = (tVec & pVec)*inv_det;
683 if (u < -tol || u > 1.0+tol)
690 const vector qVec = tVec ^ edge1;
693 const scalar v = (dir & qVec) * inv_det;
695 if (v < -tol || u + v > 1.0+tol)
702 const scalar t = (edge2 & qVec) * inv_det;
710 intersection.
hitPoint(a_ + u*edge1 + v*edge2);
717 template<
class Po
int,
class Po
intRef>
736 if (d1 <= 0.0 && d2 <= 0.0)
750 if (d3 >= 0.0 && d4 <= d3)
760 scalar vc = d1*d4 - d3*d2;
762 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
764 if ((d1 - d3) < ROOTVSMALL)
773 scalar v = d1/(d1 - d3);
775 point nearPt = a_ + v*ab;
786 if (d6 >= 0.0 && d5 <= d6)
796 scalar vb = d5*d2 - d1*d6;
798 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
800 if ((d2 - d6) < ROOTVSMALL)
809 scalar w = d2/(d2 - d6);
811 point nearPt = a_ + w*ac;
818 scalar va = d3*d6 - d5*d4;
820 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
822 if (((d4 - d3) + (d5 - d6)) < ROOTVSMALL)
832 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
834 point nearPt = b_ + w*(c_ - b_);
843 if ((va + vb + vc) < ROOTVSMALL)
847 point nearPt = centre();
853 scalar denom = 1.0/(va + vb + vc);
854 scalar v = vb * denom;
855 scalar w = vc * denom;
859 point nearPt = a_ + ab*v + ac*w;
866 template<
class Po
int,
class Po
intRef>
874 label nearLabel = -1;
876 return nearestPointClassify(
p, nearType, nearLabel);
880 template<
class Po
int,
class Po
intRef>
888 return nearestPointClassify(
p, nearType, nearLabel).hit();
892 template<
class Po
int,
class Po
intRef>
913 if (triInfo.distance() > 1)
918 scalar dist = triInfo.point().dist(lnInfo.
point());
920 triInfo.setMiss(
true);
921 triInfo.setDistance(dist);
923 else if (triInfo.distance() < 0)
928 scalar dist = triInfo.point().dist(lnInfo.
point());
930 triInfo.setMiss(
true);
931 triInfo.setDistance(dist);
938 triInfo.setDistance(0);
945 point nearestEdgePoint;
946 point nearestLinePoint;
948 scalar minDist =
ln.nearestDist
958 scalar dist =
ln.nearestDist
967 nearestEdgePoint = triEdgePoint;
968 nearestLinePoint = linePoint;
976 scalar dist =
ln.nearestDist
985 nearestEdgePoint = triEdgePoint;
986 nearestLinePoint = linePoint;
992 triInfo.setDistance(minDist);
993 triInfo.setMiss(
false);
994 triInfo.setPoint(nearestEdgePoint);
997 if (
Foam::mag(nearestLinePoint-
ln.start()) < SMALL)
1002 else if (
Foam::mag(nearestLinePoint-
ln.end()) < SMALL)
1016 template<
class Po
int,
class Po
intRef>
1023 const scalar dist = ((
p - a_) & unitNormal());
1025 return ((dist < -tol) ? -1 : (dist > tol) ? +1 : 0);
1029 template<
class Po
int,
class Po
intRef>
1037 template<
class Po
int,
class Po
intRef>
1044 template<
class Po
int,
class Po
intRef>
1054 template<
class Po
int,
class Po
intRef>
1066 template<
class Po
int,
class Po
intRef>
1072 tris_[nTris_++] = tri;
1076 template<
class Po
int,
class Po
intRef>
1085 return (d[posI]*t[negI] - d[negI]*t[posI])/(-d[negI] + d[posI]);
1091 template<
class Po
int,
class Po
intRef>
1095 triangle<Point, PointRef>& t
1099 is >> t.a_ >> t.b_ >> t.c_;
1100 is.readEnd(
"triangle");
1107 template<
class Po
int,
class Po
intRef>
1111 const triangle<Point, PointRef>& t
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
barycentric2D barycentric2D01(Random &rndGen)
Generate a random barycentric coordinate within the unit triangle.
scalar sweptVol(const triangle &t) const
Return swept-volume.
const point & c() const noexcept
The third vertex.
A triangle primitive used to calculate face normals and swept volumes. Uses referred points...
Barycentric2D< scalar > barycentric2D
A scalar version of the templated Barycentric2D.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void setPoint(const point_type &p)
Set the point.
barycentric2D pointToBarycentric(const point &pt) const
Calculate the barycentric coordinates from the given point.
scalar mag() const
The magnitude of the triangle area.
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
vector vecC() const
Edge vector opposite point c(): from a() to b()
scalar quality() const
Return quality: Ratio of triangle and circum-circle.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
Pair< Point > box() const
The enclosing (bounding) box for the triangle.
vector vecB() const
Edge vector opposite point b(): from c() to a()
tensor inertia(PointRef refPt=Zero, scalar density=1.0) const
Return the inertia tensor, with optional reference.
const dimensionedScalar c2
Second radiation constant: default SI units: [m.K].
dimensionedScalar sqrt(const dimensionedScalar &ds)
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
No type, or default initialized type.
pointHit nearestPointClassify(const point &p, label &nearType, label &nearLabel) const
Find the nearest point to p on the triangle and classify it:
Begin list [isseparator].
triPointRef tri() const
Return as triangle reference.
void flip()
Flip triangle orientation by swapping second and third vertices.
dimensionedScalar det(const dimensionedSphericalTensor &dt)
triPoints()=default
Default construct.
int sign(const point &p, const scalar tol=SMALL) const
The sign for which side of the face plane the point is on.
Point vecB() const
Edge vector opposite point b(): from c() to a()
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...
triangle(const Point &p0, const Point &p1, const Point &p2)
Construct from three points.
bool classify(const point &p, label &nearType, label &nearLabel) const
Classify nearest point to p in triangle plane.
pointHit nearestPoint(const point &p) const
Return nearest point to p on triangle.
static scalar planarTol()
Return planar tolerance.
An ordered pair of two objects of type <T> with first() and second() elements.
line< point, const point & > linePointRef
A line using referred points.
vector unitNormal() const
Return unit normal.
pointHit ray(const point &p, const vector &q, const intersection::algorithm=intersection::FULL_RAY, const intersection::direction dir=intersection::VECTOR) const
Return point intersection with a ray.
static const Identity< scalar > I
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
const wordList area
Standard area field types (scalar, vector, tensor, etc)
Point vecA() const
Edge vector opposite point a(): from b() to c()
Triangle point storage. Default constructable (triangle is not)
Point centre() const
Return centre (centroid)
void setDistance(const scalar d) noexcept
Set the distance.
scalar mag() const
The magnitude of the triangle area.
Describes the interaction of a object and a (templated) point. It carries the info of a successful hi...
scalar circumRadius() const
Return circum-radius.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
storeOp(triIntersectionList &, label &)
void setMiss(const bool eligible) noexcept
Set the hit status off and set the eligible miss status.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
vector areaNormal() const
The area normal - with magnitude equal to area of triangle.
const point & a() const noexcept
The first vertex.
Point barycentricToPoint(const barycentric2D &bary) const
Calculate the point from the given barycentric coordinates.
bool intersects(const point &origin, const vector &normal) const
Fast intersection detection with a plane.
Pair< point > box() const
The enclosing (bounding) box for the triangle.
Point vecC() const
Edge vector opposite point c(): from a() to b()
Point circumCentre() const
Return circum-centre.
vector point
Point is a vector.
vector vecA() const
Edge vector opposite point a(): from b() to c()
const point_type & hitPoint() const
Return the hit point. Fatal if not hit.
const dimensionedScalar c
Speed of light in a vacuum.
triangle< point, const point & > triPointRef
A triangle using referred points.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
const point_type & point() const noexcept
Return the point, no checks.
Point randomPoint(Random &rndGen) const
Return a random point on the triangle from a uniform distribution.
components
Component labeling enumeration.
pointHit intersection(const point &p, const vector &q, const intersection::algorithm alg, const scalar tol=0.0) const
Fast intersection with a ray.
Tensor of scalars, i.e. Tensor<scalar>.
const point & b() const noexcept
The second vertex.
vector unitNormal() const
Return unit normal.
const volScalarField & p0
point centre() const
Return centre (centroid)
PointHit< point > pointHit
A PointHit with a 3D point.
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
vector areaNormal() const
The area normal - with magnitude equal to area of triangle.
static constexpr const zero Zero
Global zero (0)