32 template<
class Po
int,
class Po
intRef>
46 template<
class Po
int,
class Po
intRef>
53 a_(points[indices[0]]),
54 b_(points[indices[1]]),
55 c_(points[indices[2]])
60 template<
class Po
int,
class Po
intRef>
69 template<
class Po
int,
class Po
intRef>
75 template<
class Po
int,
class Po
intRef>
81 template<
class Po
int,
class Po
intRef>
88 template<
class Po
int,
class Po
intRef>
91 return (1.0/3.0)*(a_ + b_ + c_);
95 template<
class Po
int,
class Po
intRef>
98 return 0.5*((b_ - a_)^(c_ - a_));
102 template<
class Po
int,
class Po
intRef>
109 template<
class Po
int,
class Po
intRef>
114 return maga > 0 ? a/maga :
Zero;
118 template<
class Po
int,
class Po
intRef>
121 scalar d1 = (c_ - a_) & (b_ - a_);
122 scalar d2 = -(c_ - b_) & (b_ - a_);
123 scalar d3 = (c_ - a_) & (c_ - b_);
129 scalar c = c1 + c2 + c3;
140 ((c2 + c3)*a_ + (c3 + c1)*b_ + (c1 + c2)*c_)/(2*c)
145 template<
class Po
int,
class Po
intRef>
148 scalar d1 = (c_ - a_) & (b_ - a_);
149 scalar d2 = -(c_ - b_) & (b_ - a_);
150 scalar d3 = (c_ - a_) & (c_ - b_);
152 scalar denom = d2*d3 + d3*d1 + d1*d2;
162 scalar a = (d1 + d2)*(d2 + d3)*(d3 + d1) / denom;
169 template<
class Po
int,
class Po
intRef>
172 scalar c = circumRadius();
184 template<
class Po
int,
class Po
intRef>
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_)))
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_)))
203 template<
class Po
int,
class Po
intRef>
210 Point aRel = a_ - refPt;
211 Point bRel = b_ - refPt;
212 Point cRel = c_ - refPt;
216 aRel.x(), aRel.y(), aRel.z(),
217 bRel.x(), bRel.y(), bRel.z(),
218 cRel.x(), cRel.y(), cRel.z()
221 scalar a =
Foam::mag((b_ - a_)^(c_ - a_));
223 tensor S = 1/24.0*(tensor::one +
I);
232 + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
240 template<
class Po
int,
class Po
intRef>
247 template<
class Po
int,
class Po
intRef>
253 return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
257 template<
class Po
int,
class Po
intRef>
264 pointToBarycentric(pt, bary);
269 template<
class Po
int,
class Po
intRef>
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;
289 scalar denom = d00*d11 - d01*d01;
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];
308 template<
class Po
int,
class Po
intRef>
319 const vector E0 = b_ - a_;
320 const vector E1 = c_ - a_;
328 if (magArea < vSmall)
346 if (dir == intersection::CONTACT_SPHERE)
350 return ray(p, q1 - n, alg, intersection::VECTOR);
362 hit = fastInter.
hit();
372 pInter = p + (q1&v)*q1;
377 const scalar dist = q1 & (pInter -
p);
379 const scalar planarPointTol =
388 )*intersection::planarTol();
391 alg == intersection::FULL_RAY
392 || (alg == intersection::HALF_RAY && dist > -planarPointTol)
394 alg == intersection::VISIBLE
395 && ((q1 & area()) < -vSmall)
411 inter.
setPoint(nearestPoint(p).rawPoint());
424 template<
class Po
int,
class Po
intRef>
433 const vector edge1 = b_ - a_;
434 const vector edge2 = c_ - a_;
437 const vector pVec = dir ^ edge2;
440 const scalar
det = edge1 & pVec;
445 if (alg == intersection::VISIBLE)
448 if (det < rootVSmall)
454 else if (alg == intersection::HALF_RAY || alg == intersection::FULL_RAY)
457 if (det > -rootVSmall && det < rootVSmall)
464 const scalar inv_det = 1.0 /
det;
467 const vector tVec = orig-a_;
470 const scalar u = (tVec & pVec)*inv_det;
472 if (u < -tol || u > 1.0+tol)
479 const vector qVec = tVec ^ edge1;
482 const scalar v = (dir & qVec) * inv_det;
484 if (v < -tol || u + v > 1.0+tol)
491 const scalar t = (edge2 & qVec) * inv_det;
493 if (alg == intersection::HALF_RAY && t < -tol)
500 intersection.
setPoint(a_ + u*edge1 + v*edge2);
507 template<
class Po
int,
class Po
intRef>
526 if (d1 <= 0.0 && d2 <= 0.0)
540 if (d3 >= 0.0 && d4 <= d3)
550 scalar vc = d1*d4 - d3*d2;
552 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
554 if ((d1 - d3) < rootVSmall)
563 scalar v = d1/(d1 - d3);
565 point nearPt = a_ + v*ab;
576 if (d6 >= 0.0 && d5 <= d6)
586 scalar vb = d5*d2 - d1*d6;
588 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
590 if ((d2 - d6) < rootVSmall)
599 scalar w = d2/(d2 - d6);
601 point nearPt = a_ + w*ac;
608 scalar va = d3*d6 - d5*d4;
610 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
612 if (((d4 - d3) + (d5 - d6)) < rootVSmall)
622 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
624 point nearPt = b_ + w*(c_ - b_);
633 if ((va + vb + vc) < rootVSmall)
637 point nearPt = centre();
643 scalar denom = 1.0/(va + vb + vc);
644 scalar v = vb * denom;
645 scalar w = vc * denom;
649 point nearPt = a_ + ab*v + ac*w;
656 template<
class Po
int,
class Po
intRef>
664 label nearLabel = -1;
666 return nearestPointClassify(p, nearType, nearLabel);
670 template<
class Po
int,
class Po
intRef>
678 return nearestPointClassify(p, nearType, nearLabel).hit();
682 template<
class Po
int,
class Po
intRef>
696 intersection::FULL_RAY
736 point nearestEdgePoint;
737 point nearestLinePoint;
758 nearestEdgePoint = triEdgePoint;
759 nearestLinePoint = linePoint;
776 nearestEdgePoint = triEdgePoint;
777 nearestLinePoint = linePoint;
810 template<
class Po
int,
class Po
intRef>
818 is >> t.a_ >> t.b_ >> t.c_;
819 is.readEnd(
"triangle");
821 is.check(
"Istream& operator>>(Istream&, triangle&)");
826 template<
class Po
int,
class Po
intRef>
835 << t.a_ << token::SPACE
836 << t.b_ << token::SPACE
barycentric2D barycentric2D01(Random &rndGen)
Generate a random barycentric coordinate within the unit triangle.
scalar sweptVol(const triangle &t) const
Return swept-volume.
Istream & readBegin(const char *funcName)
A triangle primitive used to calculate face areas and swept volumes.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const Point & c() const
Return third vertex.
Barycentric2D< scalar > barycentric2D
A scalar version of the templated Barycentric2D.
barycentric2D pointToBarycentric(const point &pt) const
Calculate the barycentric coordinates from the given point.
scalar mag() const
Return scalar magnitude.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
scalar quality() const
Return quality: Ratio of triangle and circum-circle.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
const dimensionedScalar c2
Second radiation constant: default SI units: [m.K].
dimensionedScalar sqrt(const dimensionedScalar &ds)
pointHit nearestPointClassify(const point &p, label &nearType, label &nearLabel) const
Find the nearest point to p on the triangle and classify it:
dimensionedScalar det(const dimensionedSphericalTensor &dt)
scalar minDist(const List< pointIndexHit > &hitList)
const Point & missPoint() const
Return miss point.
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...
vector area() const
Return vector area.
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.
void setDistance(const scalar d)
line< point, const point & > linePointRef
Line using referred points.
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 Point & hitPoint() const
Return hit point.
PointRef start() const
Return first vertex.
Point centre() const
Return centre (centroid)
bool hit() const
Is there a hit.
scalar circumRadius() const
Return circum-radius.
tensor inertia(PointRef refPt=vector::zero, scalar density=1.0) const
Return the inertia tensor, with optional reference.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
vector normal() const
Return unit normal.
void setMiss(const bool eligible)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
triangle(const Point &a, const Point &b, const Point &c)
Construct from three points.
const Point & rawPoint() const
Return point with no checking.
const volScalarField & cp
Point barycentricToPoint(const barycentric2D &bary) const
Calculate the point from the given barycentric coordinates.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const Point & a() const
Return first vertex.
Point vec() const
Return start-end vector.
Point circumCentre() const
Return circum-centre.
const Point & b() const
Return second vertex.
PointRef end() const
Return second vertex.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
Point randomPoint(Random &rndGen) const
Return a random point on the triangle from a uniform.
dimensioned< scalar > mag(const dimensioned< Type > &)
PointHit< point > pointHit
scalar distance() const
Return distance to hit.
pointHit intersection(const point &p, const vector &q, const intersection::algorithm alg, const scalar tol=0.0) const
Fast intersection with a ray.
void setPoint(const Point &p)
PointHit< Point > nearestDist(const Point &p) const
Return nearest distance to line from a given point.