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 const Point aRel = a_ - refPt;
186 const Point bRel = b_ - refPt;
187 const 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 const scalar a =
Foam::mag((b_ - a_)^(c_ - a_));
206 + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
213 template<
class Po
int,
class Po
intRef>
223 template<
class Po
int,
class Po
intRef>
229 return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
233 template<
class Po
int,
class Po
intRef>
240 pointToBarycentric(pt, bary);
245 template<
class Po
int,
class Po
intRef>
259 scalar d00 = v0 & v0;
260 scalar d01 = v0 & v1;
261 scalar d11 = v1 & v1;
262 scalar d20 = v2 & v0;
263 scalar d21 = v2 & v1;
265 scalar denom = d00*d11 - d01*d01;
276 bary[1] = (d11*d20 - d01*d21)/denom;
277 bary[2] = (d00*d21 - d01*d20)/denom;
278 bary[0] = 1.0 - bary[1] - bary[2];
284 template<
class Po
int,
class Po
intRef>
295 const vector E0 = b_ - a_;
296 const vector E1 = c_ - a_;
304 if (magArea < vSmall)
343 hit = fastInter.
hit();
353 pInter =
p + (q1&v)*q1;
358 const scalar dist = q1 & (pInter -
p);
360 const scalar planarPointTol =
376 && ((q1 & area()) < -vSmall)
392 inter.
setPoint(nearestPoint(
p).rawPoint());
405 template<
class Po
int,
class Po
intRef>
414 const vector edge1 = b_ - a_;
415 const vector edge2 = c_ - a_;
418 const vector pVec = dir ^ edge2;
421 const scalar
det = edge1 & pVec;
429 if (
det < rootVSmall)
442 if (
det > -rootVSmall &&
det < rootVSmall)
449 const scalar inv_det = 1.0 /
det;
452 const vector tVec = orig-a_;
455 const scalar u = (tVec & pVec)*inv_det;
457 if (u < -tol || u > 1.0+tol)
464 const vector qVec = tVec ^ edge1;
467 const scalar v = (dir & qVec) * inv_det;
469 if (v < -tol || u + v > 1.0+tol)
476 const scalar t = (edge2 & qVec) * inv_det;
492 template<
class Po
int,
class Po
intRef>
511 if (d1 <= 0.0 && d2 <= 0.0)
525 if (d3 >= 0.0 && d4 <= d3)
535 scalar vc = d1*d4 - d3*d2;
537 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
539 if ((d1 - d3) < rootVSmall)
548 scalar v = d1/(d1 - d3);
550 point nearPt = a_ + v*ab;
561 if (d6 >= 0.0 && d5 <= d6)
571 scalar vb = d5*d2 - d1*d6;
573 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
575 if ((d2 - d6) < rootVSmall)
584 scalar w = d2/(d2 - d6);
586 point nearPt = a_ + w*ac;
593 scalar va = d3*d6 - d5*d4;
595 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
597 if (((d4 - d3) + (d5 - d6)) < rootVSmall)
607 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
609 point nearPt = b_ + w*(c_ - b_);
618 if ((va + vb + vc) < rootVSmall)
622 point nearPt = centre();
628 scalar denom = 1.0/(va + vb + vc);
629 scalar v = vb * denom;
630 scalar w = vc * denom;
634 point nearPt = a_ + ab*v + ac*w;
641 template<
class Po
int,
class Po
intRef>
649 label nearLabel = -1;
651 return nearestPointClassify(
p, nearType, nearLabel);
655 template<
class Po
int,
class Po
intRef>
663 return nearestPointClassify(
p, nearType, nearLabel).hit();
667 template<
class Po
int,
class Po
intRef>
721 point nearestEdgePoint;
722 point nearestLinePoint;
734 scalar dist =
ln.nearestDist
743 nearestEdgePoint = triEdgePoint;
744 nearestLinePoint = linePoint;
752 scalar dist =
ln.nearestDist
761 nearestEdgePoint = triEdgePoint;
762 nearestLinePoint = linePoint;
773 if (
Foam::mag(nearestLinePoint-
ln.start()) < small)
778 else if (
Foam::mag(nearestLinePoint-
ln.end()) < small)
795 template<
class Po
int,
class Po
intRef>
803 is >> t.a_ >> t.b_ >> t.c_;
806 is.
check(
"Istream& operator>>(Istream&, triangle&)");
811 template<
class Po
int,
class Po
intRef>
815 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.
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.
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.
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.
void det(LagrangianPatchField< scalar > &f, const LagrangianPatchField< tensor > &f1)
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void symm(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
PointHit< point > pointHit
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
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.
barycentric2D barycentric2D01(randomGenerator &rndGen)
Generate a random barycentric coordinate within the unit triangle.
randomGenerator rndGen(653213)