32 template<
class Po
int,
class Po
intRef>
46 template<
class Po
int,
class Po
intRef>
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>
122 const scalar d1 = (c_ - a_) & (b_ - a_);
123 const scalar d2 = -(c_ - b_) & (b_ - a_);
124 const scalar d3 = (c_ - a_) & (c_ - b_);
126 const scalar
c1 = d2*d3;
127 const scalar
c2 = d3*d1;
128 const scalar c3 = d1*d2;
130 const scalar denom =
c1 +
c2 + c3;
135 static const scalar sqrt3 =
sqrt(scalar(3));
143 ((
c2 + c3)*a_ + (c3 +
c1)*b_ + (
c1 +
c2)*c_)/(2*denom),
144 sqrt(
max(0, (d1 + d2)*(d2 + d3)*(d3 + d1)/(4*denom)))
150 template<
class Po
int,
class Po
intRef>
153 const scalar r = circumCircle().second();
154 static const scalar sqrt3 =
sqrt(scalar(3));
155 return mag()/(0.75*sqrt3*
sqr(
min(r, great)) + rootVSmall);
159 template<
class Po
int,
class Po
intRef>
167 ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
168 + ((t.b_ - b_) & ((c_ - b_)^(t.a_ - b_)))
169 + ((c_ - t.c_) & ((t.b_ - t.c_)^(t.a_ - t.c_)))
171 + ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
172 + ((b_ - t.b_) & ((t.a_ - t.b_)^(t.c_ - t.b_)))
173 + ((c_ - t.c_) & ((b_ - t.c_)^(t.a_ - t.c_)))
178 template<
class Po
int,
class Po
intRef>
185 Point aRel = a_ - refPt;
186 Point bRel = b_ - refPt;
187 Point cRel = c_ - refPt;
191 aRel.x(), aRel.y(), aRel.z(),
192 bRel.x(), bRel.y(), bRel.z(),
193 cRel.x(), cRel.y(), cRel.z()
196 scalar a =
Foam::mag((b_ - a_)^(c_ - a_));
207 + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
215 template<
class Po
int,
class Po
intRef>
225 template<
class Po
int,
class Po
intRef>
231 return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
235 template<
class Po
int,
class Po
intRef>
242 pointToBarycentric(pt, bary);
247 template<
class Po
int,
class Po
intRef>
261 scalar d00 = v0 & v0;
262 scalar d01 = v0 & v1;
263 scalar d11 = v1 & v1;
264 scalar d20 = v2 & v0;
265 scalar d21 = v2 & v1;
267 scalar denom = d00*d11 - d01*d01;
278 bary[1] = (d11*d20 - d01*d21)/denom;
279 bary[2] = (d00*d21 - d01*d20)/denom;
280 bary[0] = 1.0 - bary[1] - bary[2];
286 template<
class Po
int,
class Po
intRef>
297 const vector E0 = b_ - a_;
298 const vector E1 = c_ - a_;
306 if (magArea < vSmall)
345 hit = fastInter.
hit();
355 pInter =
p + (q1&v)*q1;
360 const scalar dist = q1 & (pInter -
p);
362 const scalar planarPointTol =
378 && ((q1 & area()) < -vSmall)
394 inter.
setPoint(nearestPoint(
p).rawPoint());
407 template<
class Po
int,
class Po
intRef>
416 const vector edge1 = b_ - a_;
417 const vector edge2 = c_ - a_;
420 const vector pVec = dir ^ edge2;
423 const scalar
det = edge1 & pVec;
431 if (
det < rootVSmall)
444 if (
det > -rootVSmall &&
det < rootVSmall)
451 const scalar inv_det = 1.0 /
det;
454 const vector tVec = orig-a_;
457 const scalar u = (tVec & pVec)*inv_det;
459 if (u < -tol || u > 1.0+tol)
466 const vector qVec = tVec ^ edge1;
469 const scalar v = (dir & qVec) * inv_det;
471 if (v < -tol || u + v > 1.0+tol)
478 const scalar t = (edge2 & qVec) * inv_det;
494 template<
class Po
int,
class Po
intRef>
513 if (d1 <= 0.0 && d2 <= 0.0)
527 if (d3 >= 0.0 && d4 <= d3)
537 scalar vc = d1*d4 - d3*d2;
539 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
541 if ((d1 - d3) < rootVSmall)
550 scalar v = d1/(d1 - d3);
552 point nearPt = a_ + v*ab;
563 if (d6 >= 0.0 && d5 <= d6)
573 scalar vb = d5*d2 - d1*d6;
575 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
577 if ((d2 - d6) < rootVSmall)
586 scalar w = d2/(d2 - d6);
588 point nearPt = a_ + w*ac;
595 scalar va = d3*d6 - d5*d4;
597 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
599 if (((d4 - d3) + (d5 - d6)) < rootVSmall)
609 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
611 point nearPt = b_ + w*(c_ - b_);
620 if ((va + vb + vc) < rootVSmall)
624 point nearPt = centre();
630 scalar denom = 1.0/(va + vb + vc);
631 scalar v = vb * denom;
632 scalar w = vc * denom;
636 point nearPt = a_ + ab*v + ac*w;
643 template<
class Po
int,
class Po
intRef>
651 label nearLabel = -1;
653 return nearestPointClassify(
p, nearType, nearLabel);
657 template<
class Po
int,
class Po
intRef>
665 return nearestPointClassify(
p, nearType, nearLabel).hit();
669 template<
class Po
int,
class Po
intRef>
723 point nearestEdgePoint;
724 point nearestLinePoint;
736 scalar dist =
ln.nearestDist
745 nearestEdgePoint = triEdgePoint;
746 nearestLinePoint = linePoint;
754 scalar dist =
ln.nearestDist
763 nearestEdgePoint = triEdgePoint;
764 nearestLinePoint = linePoint;
775 if (
Foam::mag(nearestLinePoint-
ln.start()) < small)
780 else if (
Foam::mag(nearestLinePoint-
ln.end()) < small)
797 template<
class Po
int,
class Po
intRef>
805 is >> t.a_ >> t.b_ >> t.c_;
808 is.
check(
"Istream& operator>>(Istream&, triangle&)");
813 template<
class Po
int,
class Po
intRef>
817 const triangle<Point, PointRef>& t
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.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Istream & readEnd(const char *funcName)
Istream & readBegin(const char *funcName)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
const Point & hitPoint() const
Return hit point.
void setPoint(const Point &p)
void setDistance(const scalar d)
scalar distance() const
Return distance to hit.
const Point & rawPoint() const
Return point with no checking.
const Point & missPoint() const
Return miss point.
void setMiss(const bool eligible)
bool hit() const
Is there a hit.
Tensor< Cmpt > T() const
Return transpose.
A 2-tuple for storing two objects of different types.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
static Form uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
static scalar planarTol()
Return planar tolerance.
A triangle primitive used to calculate face areas and swept volumes.
barycentric2D pointToBarycentric(const point &pt) const
Calculate the barycentric coordinates from the given point.
triangle(const Point &a, const Point &b, const Point &c)
Construct from three points.
vector area() const
Return vector area.
Point barycentricToPoint(const barycentric2D &bary) const
Calculate the point from the given barycentric coordinates.
tensor inertia(PointRef refPt=vector::zero, scalar density=1.0) const
Return the inertia tensor, with optional reference.
scalar sweptVol(const triangle &t) const
Return swept-volume.
const Point & a() const
Return first vertex.
Point centre() const
Return centre (centroid)
pointHit nearestPointClassify(const point &p, label &nearType, label &nearLabel) const
Find the nearest point to p on the triangle and classify it:
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.
const Point & c() const
Return third vertex.
scalar mag() const
Return scalar magnitude.
pointHit nearestPoint(const point &p) const
Return nearest point to p on triangle.
Tuple2< Point, scalar > circumCircle() const
Return the circum centre and radius.
Point randomPoint(randomGenerator &rndGen) const
Return a random point on the triangle from a uniform.
pointHit intersection(const point &p, const vector &q, const intersection::algorithm alg, const scalar tol=0.0) const
Fast intersection with a ray.
bool classify(const point &p, label &nearType, label &nearLabel) const
Classify nearest point to p in triangle plane.
vector normal() const
Return unit normal.
const Point & b() const
Return second vertex.
scalar quality() const
Return quality: Ratio of triangle and circum-circle.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m^2].
const dimensionedScalar c2
Second radiation constant: default SI units: [m K].
const dimensionedScalar c
Speed of light in a vacuum.
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const VolField< Type > &)
dimensionedScalar det(const dimensionedSphericalTensor &dt)
scalar minDist(const List< pointIndexHit > &hitList)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
line< point, const point & > linePointRef
Line using referred points.
static const Identity< scalar > I
Barycentric2D< scalar > barycentric2D
A scalar version of the templated Barycentric2D.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
PointHit< point > pointHit
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy, recursively if necessary, the source to the destination.
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
barycentric2D barycentric2D01(randomGenerator &rndGen)
Generate a random barycentric coordinate within the unit triangle.
randomGenerator rndGen(653213)