Go to the documentation of this file.
36 template<
class Po
int,
class Po
intRef>
50 template<
class Po
int,
class Po
intRef>
62 template<
class Po
int,
class Po
intRef>
76 template<
class Po
int,
class Po
intRef>
85 template<
class Po
int,
class Po
intRef>
91 template<
class Po
int,
class Po
intRef>
97 template<
class Po
int,
class Po
intRef>
104 template<
class Po
int,
class Po
intRef>
107 return (1.0/3.0)*(a_ + b_ + c_);
111 template<
class Po
int,
class Po
intRef>
114 return 0.5*((b_ - a_)^(c_ - a_));
118 template<
class Po
int,
class Po
intRef>
123 return s < ROOTVSMALL ?
Zero :
n/
s;
127 template<
class Po
int,
class Po
intRef>
134 template<
class Po
int,
class Po
intRef>
137 scalar d1 = (c_ - a_) & (b_ - a_);
138 scalar d2 = -(c_ - b_) & (b_ - a_);
139 scalar d3 = (c_ - a_) & (c_ - b_);
145 scalar
c =
c1 +
c2 + c3;
156 ((
c2 + c3)*a_ + (c3 +
c1)*b_ + (
c1 +
c2)*c_)/(2*
c)
161 template<
class Po
int,
class Po
intRef>
164 const scalar d1 = (c_ - a_) & (b_ - a_);
165 const scalar d2 = -(c_ - b_) & (b_ - a_);
166 const scalar d3 = (c_ - a_) & (c_ - b_);
168 const scalar denom = d2*d3 + d3*d1 + d1*d2;
177 const scalar a = (d1 + d2)*(d2 + d3)*(d3 + d1) / denom;
182 template<
class Po
int,
class Po
intRef>
185 scalar
c = circumRadius();
197 template<
class Po
int,
class Po
intRef>
205 ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
206 + ((t.b_ - b_) & ((c_ - b_)^(t.a_ - b_)))
207 + ((c_ - t.c_) & ((t.b_ - t.c_)^(t.a_ - t.c_)))
209 + ((t.a_ - a_) & ((b_ - a_)^(c_ - a_)))
210 + ((b_ - t.b_) & ((t.a_ - t.b_)^(t.c_ - t.b_)))
211 + ((c_ - t.c_) & ((b_ - t.c_)^(t.a_ - t.c_)))
216 template<
class Po
int,
class Po
intRef>
223 Point aRel = a_ - refPt;
224 Point bRel = b_ - refPt;
225 Point cRel = c_ - refPt;
229 aRel.x(), aRel.y(), aRel.z(),
230 bRel.x(), bRel.y(), bRel.z(),
231 cRel.x(), cRel.y(), cRel.z()
234 scalar a =
Foam::mag((b_ - a_)^(c_ - a_));
236 tensor S = 1/24.0*(tensor::one +
I);
245 + ((aRel + bRel + cRel) & (aRel + bRel + cRel))
253 template<
class Po
int,
class Po
intRef>
260 template<
class Po
int,
class Po
intRef>
266 return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
270 template<
class Po
int,
class Po
intRef>
277 pointToBarycentric(pt, bary);
282 template<
class Po
int,
class Po
intRef>
296 scalar d00 = v0 & v0;
297 scalar d01 = v0 & v1;
298 scalar d11 = v1 & v1;
299 scalar d20 = v2 & v0;
300 scalar d21 = v2 & v1;
302 scalar denom = d00*d11 - d01*d01;
313 bary[1] = (d11*d20 - d01*d21)/denom;
314 bary[2] = (d00*d21 - d01*d20)/denom;
315 bary[0] = 1.0 - bary[1] - bary[2];
321 template<
class Po
int,
class Po
intRef>
359 if (dir == intersection::CONTACT_SPHERE)
363 return ray(
p, q1 -
n, alg, intersection::VECTOR);
374 hit = fastInter.
hit();
384 pInter =
p + (q1&v)*q1;
389 scalar dist = q1 & (pInter -
p);
391 const scalar planarPointTol =
400 )*intersection::planarTol();
403 alg == intersection::FULL_RAY
404 || (alg == intersection::HALF_RAY && dist > -planarPointTol)
406 alg == intersection::VISIBLE
407 && ((q1 & areaNormal()) < -VSMALL)
423 inter.
setPoint(nearestPoint(
p).rawPoint());
437 template<
class Po
int,
class Po
intRef>
446 const vector edge1 = b_ - a_;
447 const vector edge2 = c_ - a_;
450 const vector pVec = dir ^ edge2;
453 const scalar
det = edge1 & pVec;
458 if (alg == intersection::VISIBLE)
461 if (
det < ROOTVSMALL)
467 else if (alg == intersection::HALF_RAY || alg == intersection::FULL_RAY)
470 if (
det > -ROOTVSMALL &&
det < ROOTVSMALL)
477 const scalar inv_det = 1.0 /
det;
480 const vector tVec = orig-a_;
483 const scalar u = (tVec & pVec)*inv_det;
485 if (u < -tol || u > 1.0+tol)
492 const vector qVec = tVec ^ edge1;
495 const scalar v = (dir & qVec) * inv_det;
497 if (v < -tol || u + v > 1.0+tol)
504 const scalar t = (edge2 & qVec) * inv_det;
506 if (alg == intersection::HALF_RAY && t < -tol)
520 template<
class Po
int,
class Po
intRef>
539 if (d1 <= 0.0 && d2 <= 0.0)
553 if (d3 >= 0.0 && d4 <= d3)
563 scalar vc = d1*d4 - d3*d2;
565 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
567 if ((d1 - d3) < ROOTVSMALL)
576 scalar v = d1/(d1 - d3);
578 point nearPt = a_ + v*ab;
589 if (d6 >= 0.0 && d5 <= d6)
599 scalar vb = d5*d2 - d1*d6;
601 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
603 if ((d2 - d6) < ROOTVSMALL)
612 scalar w = d2/(d2 - d6);
614 point nearPt = a_ + w*ac;
621 scalar va = d3*d6 - d5*d4;
623 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
625 if (((d4 - d3) + (d5 - d6)) < ROOTVSMALL)
635 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
637 point nearPt = b_ + w*(c_ - b_);
646 if ((va + vb + vc) < ROOTVSMALL)
650 point nearPt = centre();
656 scalar denom = 1.0/(va + vb + vc);
657 scalar v = vb * denom;
658 scalar w = vc * denom;
662 point nearPt = a_ + ab*v + ac*w;
669 template<
class Po
int,
class Po
intRef>
677 label nearLabel = -1;
679 return nearestPointClassify(
p, nearType, nearLabel);
683 template<
class Po
int,
class Po
intRef>
691 return nearestPointClassify(
p, nearType, nearLabel).hit();
695 template<
class Po
int,
class Po
intRef>
709 intersection::FULL_RAY
749 point nearestEdgePoint;
750 point nearestLinePoint;
752 scalar minDist =
ln.nearestDist
762 scalar dist =
ln.nearestDist
771 nearestEdgePoint = triEdgePoint;
772 nearestLinePoint = linePoint;
780 scalar dist =
ln.nearestDist
789 nearestEdgePoint = triEdgePoint;
790 nearestLinePoint = linePoint;
801 if (
Foam::mag(nearestLinePoint-
ln.start()) < SMALL)
806 else if (
Foam::mag(nearestLinePoint-
ln.end()) < SMALL)
821 template<
class Po
int,
class Po
intRef>
828 const scalar dist = ((
p - a_) & unitNormal());
830 return ((dist < -tol) ? -1 : (dist > tol) ? +1 : 0);
834 template<
class Po
int,
class Po
intRef>
842 template<
class Po
int,
class Po
intRef>
849 template<
class Po
int,
class Po
intRef>
859 template<
class Po
int,
class Po
intRef>
871 template<
class Po
int,
class Po
intRef>
877 tris_[nTris_++] = tri;
881 template<
class Po
int,
class Po
intRef>
890 return (d[posI]*t[negI] - d[negI]*t[posI])/(-d[negI] + d[posI]);
896 template<
class Po
int,
class Po
intRef>
904 is >> t.a_ >> t.b_ >> t.c_;
905 is.readEnd(
"triangle");
912 template<
class Po
int,
class Po
intRef>
916 const triangle<Point, PointRef>& t
void setMiss(const bool eligible)
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
bool hit() const
Is there a hit.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Point randomPoint(Random &rndGen) const
Return a random point on the triangle from a uniform.
const volScalarField & cp
static constexpr const zero Zero
Global zero (0)
int sign(const point &p, const scalar tol=SMALL) const
The sign for which side of the face plane the point is on.
bool classify(const point &p, label &nearType, label &nearLabel) const
Classify nearest point to p in triangle plane.
const Point & rawPoint() const
Return point with no checking.
tensor inertia(PointRef refPt=Zero, scalar density=1.0) const
Return the inertia tensor, with optional reference.
Templated 2D Barycentric derived from VectorSpace. Has 3 components, one of which is redundant.
Barycentric2D< scalar > barycentric2D
A scalar version of the templated Barycentric2D.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Point centre() const
Return centre (centroid)
vector unitNormal() const
Return unit normal.
A triangle primitive used to calculate face normals and swept volumes.
Triangle storage. Null constructable (unfortunately triangle<point, point> is not)
scalar distance() const
Return distance to hit.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
const Point & c() const
Return third vertex.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void setPoint(const Point &p)
const Point & a() const
Return first vertex.
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.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
const Point & b() const
Return second vertex.
scalar circumRadius() const
Return circum-radius.
PointHit< point > pointHit
const dimensionedScalar c2
Second radiation constant: default SI units: [m.K].
scalar mag() const
Return scalar magnitude.
pointHit nearestPointClassify(const point &p, label &nearType, label &nearLabel) const
Find the nearest point to p on the triangle and classify it:
line< point, const point & > linePointRef
Line using referred points.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
barycentric2D barycentric2D01(Random &rndGen)
Generate a random barycentric coordinate within the unit triangle.
scalar quality() const
Return quality: Ratio of triangle and circum-circle.
Point circumCentre() const
Return circum-centre.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A 1D vector of objects of type <T> with a fixed length <N>.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
pointHit intersection(const point &p, const vector &q, const intersection::algorithm alg, const scalar tol=0.0) const
Fast intersection with a ray.
const wordList area
Standard area field types (scalar, vector, tensor, etc)
triangle(const Point &a, const Point &b, const Point &c)
Construct from three points.
const dimensionedScalar c
Speed of light in a vacuum.
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
pointHit nearestPoint(const point &p) const
Return nearest point to p on triangle.
dimensionedScalar det(const dimensionedSphericalTensor &dt)
barycentric2D pointToBarycentric(const point &pt) const
Calculate the barycentric coordinates from the given point.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Point barycentricToPoint(const barycentric2D &bary) const
Calculate the point from the given barycentric coordinates.
vector areaNormal() const
The area normal - with magnitude equal to area of triangle.
const Point & missPoint() const
Return miss point.
Begin list [isseparator].
const Point & hitPoint() const
Return hit point.
scalar sweptVol(const triangle &t) const
Return swept-volume.
static const Identity< scalar > I
storeOp(triIntersectionList &, label &)
void setDistance(const scalar d)