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>
102 template<
class Po
int,
class Po
intRef>
105 return 0.5*((b_ - a_)^(c_ - a_));
109 template<
class Po
int,
class Po
intRef>
112 scalar d1 = (c_ - a_) & (b_ - a_);
113 scalar d2 = -(c_ - b_) & (b_ - a_);
114 scalar d3 = (c_ - a_) & (c_ - b_);
120 scalar c = c1 + c2 + c3;
131 ((c2 + c3)*a_ + (c3 + c1)*b_ + (c1 + c2)*c_)/(2*c)
136 template<
class Po
int,
class Po
intRef>
139 scalar d1 = (c_ - a_) & (b_ - a_);
140 scalar d2 = -(c_ - b_) & (b_ - a_);
141 scalar d3 = (c_ - a_) & (c_ - b_);
143 scalar denom = d2*d3 + d3*d1 + d1*d2;
153 scalar a = (d1 + d2)*(d2 + d3)*(d3 + d1) / denom;
160 template<
class Po
int,
class Po
intRef>
163 scalar c = circumRadius();
175 template<
class Po
int,
class Po
intRef>
183 ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
184 + ((t.b_ - b_) & ((c_ - b_)^(t.a_ - b_)))
185 + ((c_ - t.c_) & ((t.b_ - t.c_)^(t.a_ - t.c_)))
187 + ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
188 + ((b_ - t.b_) & ((t.a_ - t.b_)^(t.c_ - t.b_)))
189 + ((c_ - t.c_) & ((b_ - t.c_)^(t.a_ - t.c_)))
194 template<
class Po
int,
class Po
intRef>
201 Point aRel = a_ - refPt;
202 Point bRel = b_ - refPt;
203 Point cRel = c_ - refPt;
207 aRel.x(), aRel.y(), aRel.z(),
208 bRel.x(), bRel.y(), bRel.z(),
209 cRel.x(), cRel.y(), cRel.z()
212 scalar a =
Foam::mag((b_ - a_)^(c_ - a_));
214 tensor S = 1/24.0*(tensor::one +
I);
223 + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
231 template<
class Po
int,
class Po
intRef>
238 template<
class Po
int,
class Po
intRef>
248 template<
class Po
int,
class Po
intRef>
254 return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
258 template<
class Po
int,
class Po
intRef>
265 pointToBarycentric(pt, bary);
270 template<
class Po
int,
class Po
intRef>
284 scalar d00 = v0 & v0;
285 scalar d01 = v0 & v1;
286 scalar d11 = v1 & v1;
287 scalar d20 = v2 & v0;
288 scalar d21 = v2 & v1;
290 scalar denom = d00*d11 - d01*d01;
301 bary[1] = (d11*d20 - d01*d21)/denom;
302 bary[2] = (d00*d21 - d01*d20)/denom;
303 bary[0] = 1.0 - bary[1] - bary[2];
309 template<
class Po
int,
class Po
intRef>
347 if (dir == intersection::CONTACT_SPHERE)
351 return ray(p, q1 - n, alg, intersection::VECTOR);
362 hit = fastInter.
hit();
372 pInter = p + (q1&v)*q1;
377 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 &
normal()) < -VSMALL)
411 inter.
setPoint(nearestPoint(p).rawPoint());
425 template<
class Po
int,
class Po
intRef>
434 const vector edge1 = b_ - a_;
435 const vector edge2 = c_ - a_;
438 const vector pVec = dir ^ edge2;
441 const scalar
det = edge1 & pVec;
446 if (alg == intersection::VISIBLE)
449 if (det < ROOTVSMALL)
455 else if (alg == intersection::HALF_RAY || alg == intersection::FULL_RAY)
458 if (det > -ROOTVSMALL && det < ROOTVSMALL)
465 const scalar inv_det = 1.0 /
det;
468 const vector tVec = orig-a_;
471 const scalar u = (tVec & pVec)*inv_det;
473 if (u < -tol || u > 1.0+tol)
480 const vector qVec = tVec ^ edge1;
483 const scalar v = (dir & qVec) * inv_det;
485 if (v < -tol || u + v > 1.0+tol)
492 const scalar t = (edge2 & qVec) * inv_det;
494 if (alg == intersection::HALF_RAY && t < -tol)
501 intersection.
setPoint(a_ + u*edge1 + v*edge2);
508 template<
class Po
int,
class Po
intRef>
527 if (d1 <= 0.0 && d2 <= 0.0)
541 if (d3 >= 0.0 && d4 <= d3)
551 scalar vc = d1*d4 - d3*d2;
553 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
555 if ((d1 - d3) < ROOTVSMALL)
564 scalar v = d1/(d1 - d3);
566 point nearPt = a_ + v*ab;
577 if (d6 >= 0.0 && d5 <= d6)
587 scalar vb = d5*d2 - d1*d6;
589 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
591 if ((d2 - d6) < ROOTVSMALL)
600 scalar w = d2/(d2 - d6);
602 point nearPt = a_ + w*ac;
609 scalar va = d3*d6 - d5*d4;
611 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
613 if (((d4 - d3) + (d5 - d6)) < ROOTVSMALL)
623 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
625 point nearPt = b_ + w*(c_ - b_);
634 if ((va + vb + vc) < ROOTVSMALL)
638 point nearPt = centre();
644 scalar denom = 1.0/(va + vb + vc);
645 scalar v = vb * denom;
646 scalar w = vc * denom;
650 point nearPt = a_ + ab*v + ac*w;
657 template<
class Po
int,
class Po
intRef>
665 label nearLabel = -1;
667 return nearestPointClassify(p, nearType, nearLabel);
671 template<
class Po
int,
class Po
intRef>
679 return nearestPointClassify(p, nearType, nearLabel).hit();
683 template<
class Po
int,
class Po
intRef>
697 intersection::FULL_RAY
737 point nearestEdgePoint;
738 point nearestLinePoint;
759 nearestEdgePoint = triEdgePoint;
760 nearestLinePoint = linePoint;
777 nearestEdgePoint = triEdgePoint;
778 nearestLinePoint = linePoint;
811 template<
class Po
int,
class Po
intRef>
819 is >> t.a_ >> t.b_ >> t.c_;
820 is.readEnd(
"triangle");
822 is.check(
"Istream& operator>>(Istream&, triangle&)");
827 template<
class Po
int,
class Po
intRef>
836 << t.a_ << token::SPACE
837 << t.b_ << token::SPACE
scalar sweptVol(const triangle &t) const
Return swept-volume.
Istream & readBegin(const char *funcName)
A triangle primitive used to calculate face normals 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)
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...
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...
Simple random number generator.
vector normal() const
Return vector 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 > &)
Foam::barycentric2D barycentric2D01(Foam::scalar s, Foam::scalar t)
const Point & a() const
Return first vertex.
A normal distribution model.
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.