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::direction::contactSphere)
365 intersection::algorithm::fullRay
367 hit = fastInter.
hit();
377 pInter = p + (q1&v)*q1;
382 const scalar dist = q1 & (pInter -
p);
384 const scalar planarPointTol =
393 )*intersection::planarTol();
396 alg == intersection::algorithm::fullRay
397 || (alg == intersection::algorithm::halfRay && dist > -planarPointTol)
399 alg == intersection::algorithm::visible
400 && ((q1 & area()) < -vSmall)
416 inter.
setPoint(nearestPoint(p).rawPoint());
429 template<
class Po
int,
class Po
intRef>
438 const vector edge1 = b_ - a_;
439 const vector edge2 = c_ - a_;
442 const vector pVec = dir ^ edge2;
445 const scalar
det = edge1 & pVec;
450 if (alg == intersection::algorithm::visible)
453 if (det < rootVSmall)
461 alg == intersection::algorithm::halfRay
462 || alg == intersection::algorithm::fullRay
466 if (det > -rootVSmall && det < rootVSmall)
473 const scalar inv_det = 1.0 /
det;
476 const vector tVec = orig-a_;
479 const scalar u = (tVec & pVec)*inv_det;
481 if (u < -tol || u > 1.0+tol)
488 const vector qVec = tVec ^ edge1;
491 const scalar v = (dir & qVec) * inv_det;
493 if (v < -tol || u + v > 1.0+tol)
500 const scalar t = (edge2 & qVec) * inv_det;
502 if (alg == intersection::algorithm::halfRay && t < -tol)
509 intersection.
setPoint(a_ + u*edge1 + v*edge2);
516 template<
class Po
int,
class Po
intRef>
535 if (d1 <= 0.0 && d2 <= 0.0)
549 if (d3 >= 0.0 && d4 <= d3)
559 scalar vc = d1*d4 - d3*d2;
561 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
563 if ((d1 - d3) < rootVSmall)
572 scalar v = d1/(d1 - d3);
574 point nearPt = a_ + v*ab;
585 if (d6 >= 0.0 && d5 <= d6)
595 scalar vb = d5*d2 - d1*d6;
597 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
599 if ((d2 - d6) < rootVSmall)
608 scalar w = d2/(d2 - d6);
610 point nearPt = a_ + w*ac;
617 scalar va = d3*d6 - d5*d4;
619 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
621 if (((d4 - d3) + (d5 - d6)) < rootVSmall)
631 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
633 point nearPt = b_ + w*(c_ - b_);
642 if ((va + vb + vc) < rootVSmall)
646 point nearPt = centre();
652 scalar denom = 1.0/(va + vb + vc);
653 scalar v = vb * denom;
654 scalar w = vc * denom;
658 point nearPt = a_ + ab*v + ac*w;
665 template<
class Po
int,
class Po
intRef>
673 label nearLabel = -1;
675 return nearestPointClassify(p, nearType, nearLabel);
679 template<
class Po
int,
class Po
intRef>
687 return nearestPointClassify(p, nearType, nearLabel).hit();
691 template<
class Po
int,
class Po
intRef>
705 intersection::algorithm::fullRay
745 point nearestEdgePoint;
746 point nearestLinePoint;
767 nearestEdgePoint = triEdgePoint;
768 nearestLinePoint = linePoint;
785 nearestEdgePoint = triEdgePoint;
786 nearestLinePoint = linePoint;
819 template<
class Po
int,
class Po
intRef>
827 is >> t.a_ >> t.b_ >> t.c_;
828 is.readEnd(
"triangle");
830 is.check(
"Istream& operator>>(Istream&, triangle&)");
835 template<
class Po
int,
class Po
intRef>
844 << t.a_ << token::SPACE
845 << 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.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
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.
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)...
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.
pointHit nearestPointClassify(const point &p, label &nearType, label &nearLabel) const
Find the nearest point to p on the triangle and classify it:
Vector< scalar > vector
A scalar version of the templated Vector.
dimensionedScalar det(const dimensionedSphericalTensor &dt)
scalar minDist(const List< pointIndexHit > &hitList)
const Point & missPoint() const
Return miss point.
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...
vector area() const
Return vector area.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m^2].
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.
static const Identity< scalar > I
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const GeometricField< Type, fvPatchField, volMesh > &)
const Point & hitPoint() const
Return hit point.
PointRef start() const
Return first vertex.
Point centre() const
Return centre (centroid)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
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.
Point barycentricToPoint(const barycentric2D &bary) const
Calculate the point from the given barycentric coordinates.
const Point & a() const
Return first vertex.
Point vec() const
Return start-end vector.
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.
Point circumCentre() const
Return circum-centre.
const Point & b() const
Return second vertex.
PointRef end() const
Return second vertex.
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.