86 template<
class Po
int,
class Po
intRef>
100 template<
class Po
int,
class Po
intRef>
106 a_(
pts.template
get<0>()),
112 template<
class Po
int,
class Po
intRef>
125 template<
class Po
int,
class Po
intRef>
140 template<
class Po
int,
class Po
intRef>
149 template<
class Po
int,
class Po
intRef>
157 return (1.0/3.0)*(
p0 + p1 + p2);
161 template<
class Po
int,
class Po
intRef>
164 return (1.0/3.0)*(a_ + b_ + c_);
174 template<
class Po
int,
class Po
intRef>
182 return 0.5*((p1 -
p0)^(p2 -
p0));
186 template<
class Po
int,
class Po
intRef>
189 return 0.5*((b_ - a_)^(c_ - a_));
199 template<
class Po
int,
class Po
intRef>
208 (void)
n.normalise(ROOTVSMALL);
213 template<
class Po
int,
class Po
intRef>
226 template<
class Po
int,
class Po
intRef>
242 template<
class Po
int,
class Po
intRef>
255 template<
class Po
int,
class Po
intRef>
258 return Point(c_ - b_);
261 template<
class Po
int,
class Po
intRef>
264 return Point(a_ - c_);
267 template<
class Po
int,
class Po
intRef>
270 return Point(b_ - a_);
315 template<
class Po
int,
class Po
intRef>
322 template<
class Po
int,
class Po
intRef>
325 scalar d1 = (c_ - a_) & (b_ - a_);
326 scalar d2 = -(c_ - b_) & (b_ - a_);
327 scalar d3 = (c_ - a_) & (c_ - b_);
333 scalar
c =
c1 +
c2 + c3;
344 ((
c2 + c3)*a_ + (c3 +
c1)*b_ + (
c1 +
c2)*c_)/(2*
c)
349 template<
class Po
int,
class Po
intRef>
352 const scalar d1 = (c_ - a_) & (b_ - a_);
353 const scalar d2 = -(c_ - b_) & (b_ - a_);
354 const scalar d3 = (c_ - a_) & (c_ - b_);
356 const scalar denom = d2*d3 + d3*d1 + d1*d2;
365 const scalar a = (d1 + d2)*(d2 + d3)*(d3 + d1) / denom;
370 template<
class Po
int,
class Po
intRef>
373 scalar
c = circumRadius();
385 template<
class Po
int,
class Po
intRef>
393 ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
394 + ((t.b_ - b_) & ((c_ - b_)^(t.a_ - b_)))
395 + ((c_ - t.c_) & ((t.b_ - t.c_)^(t.a_ - t.c_)))
397 + ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
398 + ((b_ - t.b_) & ((t.a_ - t.b_)^(t.c_ - t.b_)))
399 + ((c_ - t.c_) & ((b_ - t.c_)^(t.a_ - t.c_)))
404 template<
class Po
int,
class Po
intRef>
411 Point aRel = a_ - refPt;
412 Point bRel = b_ - refPt;
413 Point cRel = c_ - refPt;
417 aRel.x(), aRel.y(), aRel.z(),
418 bRel.x(), bRel.y(), bRel.z(),
419 cRel.x(), cRel.y(), cRel.z()
422 scalar a =
Foam::mag((b_ - a_)^(c_ - a_));
424 tensor S = 1/24.0*(tensor::one +
I);
433 + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
441 template<
class Po
int,
class Po
intRef>
448 template<
class Po
int,
class Po
intRef>
454 return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
458 template<
class Po
int,
class Po
intRef>
465 pointToBarycentric(pt, bary);
470 template<
class Po
int,
class Po
intRef>
484 scalar d00 = v0 & v0;
485 scalar d01 = v0 & v1;
486 scalar d11 = v1 & v1;
487 scalar d20 = v2 & v0;
488 scalar d21 = v2 & v1;
490 scalar denom = d00*d11 - d01*d01;
501 bary[1] = (d11*d20 - d01*d21)/denom;
502 bary[2] = (d00*d21 - d01*d20)/denom;
503 bary[0] = 1.0 - bary[1] - bary[2];
509 template<
class Po
int,
class Po
intRef>
521 (((a_ - origin) & normal) < 0 ? 1 : 2)
522 | (((b_ - origin) & normal) < 0 ? 1 : 2)
523 | (((c_ - origin) & normal) < 0 ? 1 : 2)
529 template<
class Po
int,
class Po
intRef>
541 (a_[axis] < origin[axis] ? 1 : 2)
542 | (b_[axis] < origin[axis] ? 1 : 2)
543 | (c_[axis] < origin[axis] ? 1 : 2)
549 template<
class Po
int,
class Po
intRef>
602 hit = fastInter.hit();
606 pInter = fastInter.point();
612 pInter =
p + (q1&v)*q1;
617 scalar dist = q1 & (pInter -
p);
619 const scalar planarPointTol =
635 && ((q1 & areaNormal()) < -VSMALL)
664 template<
class Po
int,
class Po
intRef>
673 const vector edge1 = b_ - a_;
674 const vector edge2 = c_ - a_;
677 const vector pVec = dir ^ edge2;
680 const scalar
det = edge1 & pVec;
688 if (
det < ROOTVSMALL)
697 if (
det > -ROOTVSMALL &&
det < ROOTVSMALL)
704 const scalar inv_det = 1.0 /
det;
707 const vector tVec = orig-a_;
710 const scalar u = (tVec & pVec)*inv_det;
712 if (u < -tol || u > 1.0+tol)
719 const vector qVec = tVec ^ edge1;
722 const scalar v = (dir & qVec) * inv_det;
724 if (v < -tol || u + v > 1.0+tol)
731 const scalar t = (edge2 & qVec) * inv_det;
739 intersection.
hitPoint(a_ + u*edge1 + v*edge2);
746 template<
class Po
int,
class Po
intRef>
765 if (d1 <= 0.0 && d2 <= 0.0)
779 if (d3 >= 0.0 && d4 <= d3)
789 scalar vc = d1*d4 - d3*d2;
791 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
793 if ((d1 - d3) < ROOTVSMALL)
802 scalar v = d1/(d1 - d3);
804 point nearPt = a_ + v*ab;
815 if (d6 >= 0.0 && d5 <= d6)
825 scalar vb = d5*d2 - d1*d6;
827 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
829 if ((d2 - d6) < ROOTVSMALL)
838 scalar w = d2/(d2 - d6);
840 point nearPt = a_ + w*ac;
847 scalar va = d3*d6 - d5*d4;
849 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
851 if (((d4 - d3) + (d5 - d6)) < ROOTVSMALL)
861 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
863 point nearPt = b_ + w*(c_ - b_);
872 if ((va + vb + vc) < ROOTVSMALL)
876 point nearPt = centre();
882 scalar denom = 1.0/(va + vb + vc);
883 scalar v = vb * denom;
884 scalar w = vc * denom;
888 point nearPt = a_ + ab*v + ac*w;
895 template<
class Po
int,
class Po
intRef>
903 label nearLabel = -1;
905 return nearestPointClassify(
p, nearType, nearLabel);
909 template<
class Po
int,
class Po
intRef>
917 return nearestPointClassify(
p, nearType, nearLabel).hit();
921 template<
class Po
int,
class Po
intRef>
942 if (triInfo.distance() > 1)
947 scalar dist = triInfo.point().dist(lnInfo.
point());
949 triInfo.setMiss(
true);
950 triInfo.setDistance(dist);
952 else if (triInfo.distance() < 0)
957 scalar dist = triInfo.point().dist(lnInfo.
point());
959 triInfo.setMiss(
true);
960 triInfo.setDistance(dist);
967 triInfo.setDistance(0);
974 point nearestEdgePoint;
975 point nearestLinePoint;
977 scalar minDist =
ln.nearestDist
987 scalar dist =
ln.nearestDist
996 nearestEdgePoint = triEdgePoint;
997 nearestLinePoint = linePoint;
1005 scalar dist =
ln.nearestDist
1014 nearestEdgePoint = triEdgePoint;
1015 nearestLinePoint = linePoint;
1021 triInfo.setDistance(minDist);
1022 triInfo.setMiss(
false);
1023 triInfo.setPoint(nearestEdgePoint);
1026 if (
Foam::mag(nearestLinePoint-
ln.start()) < SMALL)
1031 else if (
Foam::mag(nearestLinePoint-
ln.end()) < SMALL)
1045 template<
class Po
int,
class Po
intRef>
1052 const scalar dist = ((
p - a_) & unitNormal());
1054 return ((dist < -tol) ? -1 : (dist > tol) ? +1 : 0);
1058 template<
class Po
int,
class Po
intRef>
1066 template<
class Po
int,
class Po
intRef>
1073 template<
class Po
int,
class Po
intRef>
1083 template<
class Po
int,
class Po
intRef>
1095 template<
class Po
int,
class Po
intRef>
1101 tris_[nTris_++] = tri;
1105 template<
class Po
int,
class Po
intRef>
1114 return (d[posI]*t[negI] - d[negI]*t[posI])/(-d[negI] + d[posI]);
1120 template<
class Po
int,
class Po
intRef>
1124 triangle<Point, PointRef>& t
1128 is >> t.a_ >> t.b_ >> t.c_;
1129 is.readEnd(
"triangle");
1136 template<
class Po
int,
class Po
intRef>
1140 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)