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;
142 ((
c2 + c3)*a_ + (c3 +
c1)*b_ + (
c1 +
c2)*c_)/(2*denom),
143 max(0, (d1 + d2)*(d2 + d3)*(d3 + d1)/(4*denom))
149 template<
class Po
int,
class Po
intRef>
156 if (crSqr.
second() < 0)
return crSqr;
162 template<
class Po
int,
class Po
intRef>
165 const scalar r = circumCircle().second();
170 static const scalar sqrt3 =
sqrt(scalar(3));
172 return mag()/(0.75*sqrt3*
sqr(
min(r, great)) + rootVSmall);
176 template<
class Po
int,
class Po
intRef>
184 ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
185 + ((t.b_ - b_) & ((c_ - b_)^(t.a_ - b_)))
186 + ((c_ - t.c_) & ((t.b_ - t.c_)^(t.a_ - t.c_)))
188 + ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
189 + ((b_ - t.b_) & ((t.a_ - t.b_)^(t.c_ - t.b_)))
190 + ((c_ - t.c_) & ((b_ - t.c_)^(t.a_ - t.c_)))
195 template<
class Po
int,
class Po
intRef>
202 const Point aRel = a_ - refPt;
203 const Point bRel = b_ - refPt;
204 const Point cRel = c_ - refPt;
208 aRel.x(), aRel.y(), aRel.z(),
209 bRel.x(), bRel.y(), bRel.z(),
210 cRel.x(), cRel.y(), cRel.z()
213 const scalar a =
Foam::mag((b_ - a_)^(c_ - a_));
223 + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
230 template<
class Po
int,
class Po
intRef>
240 template<
class Po
int,
class Po
intRef>
246 return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
250 template<
class Po
int,
class Po
intRef>
257 pointToBarycentric(pt, bary);
262 template<
class Po
int,
class Po
intRef>
276 scalar d00 = v0 & v0;
277 scalar d01 = v0 & v1;
278 scalar d11 = v1 & v1;
279 scalar d20 = v2 & v0;
280 scalar d21 = v2 & v1;
282 scalar denom = d00*d11 - d01*d01;
293 bary[1] = (d11*d20 - d01*d21)/denom;
294 bary[2] = (d00*d21 - d01*d20)/denom;
295 bary[0] = 1.0 - bary[1] - bary[2];
301 template<
class Po
int,
class Po
intRef>
312 const vector E0 = b_ - a_;
313 const vector E1 = c_ - a_;
321 if (magArea < vSmall)
360 hit = fastInter.
hit();
370 pInter =
p + (q1&v)*q1;
375 const scalar dist = q1 & (pInter -
p);
377 const scalar planarPointTol =
393 && ((q1 &
area()) < -vSmall)
409 inter.
setPoint(nearestPoint(
p).rawPoint());
422 template<
class Po
int,
class Po
intRef>
431 const vector edge1 = b_ - a_;
432 const vector edge2 = c_ - a_;
435 const vector pVec = dir ^ edge2;
438 const scalar
det = edge1 & pVec;
446 if (
det < rootVSmall)
459 if (
det > -rootVSmall &&
det < rootVSmall)
466 const scalar inv_det = 1.0 /
det;
469 const vector tVec = orig-a_;
472 const scalar u = (tVec & pVec)*inv_det;
474 if (u < -tol || u > 1.0+tol)
481 const vector qVec = tVec ^ edge1;
484 const scalar v = (dir & qVec) * inv_det;
486 if (v < -tol || u + v > 1.0+tol)
493 const scalar t = (edge2 & qVec) * inv_det;
509 template<
class Po
int,
class Po
intRef>
528 if (d1 <= 0.0 && d2 <= 0.0)
542 if (d3 >= 0.0 && d4 <= d3)
552 scalar vc = d1*d4 - d3*d2;
554 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
556 if ((d1 - d3) < rootVSmall)
565 scalar v = d1/(d1 - d3);
567 point nearPt = a_ + v*ab;
578 if (d6 >= 0.0 && d5 <= d6)
588 scalar vb = d5*d2 - d1*d6;
590 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
592 if ((d2 - d6) < rootVSmall)
601 scalar w = d2/(d2 - d6);
603 point nearPt = a_ + w*ac;
610 scalar va = d3*d6 - d5*d4;
612 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
614 if (((d4 - d3) + (d5 - d6)) < rootVSmall)
624 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
626 point nearPt = b_ + w*(c_ - b_);
635 if ((va + vb + vc) < rootVSmall)
639 point nearPt = centre();
645 scalar denom = 1.0/(va + vb + vc);
646 scalar v = vb * denom;
647 scalar w = vc * denom;
651 point nearPt = a_ + ab*v + ac*w;
658 template<
class Po
int,
class Po
intRef>
666 label nearLabel = -1;
668 return nearestPointClassify(
p, nearType, nearLabel);
672 template<
class Po
int,
class Po
intRef>
680 return nearestPointClassify(
p, nearType, nearLabel).hit();
684 template<
class Po
int,
class Po
intRef>
738 point nearestEdgePoint;
739 point nearestLinePoint;
751 scalar dist =
ln.nearestDist
760 nearestEdgePoint = triEdgePoint;
761 nearestLinePoint = linePoint;
769 scalar dist =
ln.nearestDist
778 nearestEdgePoint = triEdgePoint;
779 nearestLinePoint = linePoint;
790 if (
Foam::mag(nearestLinePoint-
ln.start()) < small)
795 else if (
Foam::mag(nearestLinePoint-
ln.end()) < small)
812 template<
class Po
int,
class Po
intRef>
820 is >> t.a_ >> t.b_ >> t.c_;
823 is.
check(
"Istream& operator>>(Istream&, triangle&)");
828 template<
class Po
int,
class Po
intRef>
832 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.
const Type2 & second() const
Return second.
const Type1 & first() const
Return first.
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.
scalar sweptVol(const triangle &t) const
Return swept-volume.
const Point & a() const
Return first vertex.
Point centre() const
Return centre (centroid)
Tuple2< Point, scalar > circumCircleSqr() const
Return the circum-centre and radius-squared.
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.
symmTensor inertia(PointRef refPt=vector::zero, scalar density=1.0) const
Return the inertia tensor, with optional reference.
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.
const dimensionSet density
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const VolField< Type > &)
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.
line< point, const point & > linePointRef
Line using referred points.
static const Identity< scalar > I
Barycentric2D< scalar > barycentric2D
A scalar version of the templated Barycentric2D.
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void symm(pointPatchField< tensor > &, const pointPatchField< tensor > &)
PointHit< point > pointHit
void det(pointPatchField< scalar > &, const pointPatchField< tensor > &)
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy, recursively if necessary, the source to the destination.
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
barycentric2D barycentric2D01(randomGenerator &rndGen)
Generate a random barycentric coordinate within the unit triangle.
randomGenerator rndGen(653213)