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>
243 return (1 - t)*a_ + (1 -
s)*t*b_ + s*t*c_;
247 template<
class Po
int,
class Po
intRef>
262 return (1 - t)*a_ + (1 -
s)*t*b_ + s*t*c_;
266 template<
class Po
int,
class Po
intRef>
280 scalar d00 = v0 & v0;
281 scalar d01 = v0 & v1;
282 scalar d11 = v1 & v1;
283 scalar d20 = v2 & v0;
284 scalar d21 = v2 & v1;
286 scalar denom = d00*d11 - d01*d01;
299 bary[1] = (d11*d20 - d01*d21)/denom;
300 bary[2] = (d00*d21 - d01*d20)/denom;
301 bary[0] = 1.0 - bary[1] - bary[2];
307 template<
class Po
int,
class Po
intRef>
345 if (dir == intersection::CONTACT_SPHERE)
349 return ray(p, q1 - n, alg, intersection::VECTOR);
360 hit = fastInter.
hit();
370 pInter = p + (q1&v)*q1;
375 scalar dist = q1 & (pInter -
p);
377 const scalar planarPointTol =
386 )*intersection::planarTol();
389 alg == intersection::FULL_RAY
390 || (alg == intersection::HALF_RAY && dist > -planarPointTol)
392 alg == intersection::VISIBLE
393 && ((q1 &
normal()) < -VSMALL)
409 inter.
setPoint(nearestPoint(p).rawPoint());
423 template<
class Po
int,
class Po
intRef>
432 const vector edge1 = b_ - a_;
433 const vector edge2 = c_ - a_;
436 const vector pVec = dir ^ edge2;
439 const scalar
det = edge1 & pVec;
444 if (alg == intersection::VISIBLE)
447 if (det < ROOTVSMALL)
453 else if (alg == intersection::HALF_RAY || alg == intersection::FULL_RAY)
456 if (det > -ROOTVSMALL && det < ROOTVSMALL)
463 const scalar inv_det = 1.0 /
det;
466 const vector tVec = orig-a_;
469 const scalar u = (tVec & pVec)*inv_det;
471 if (u < -tol || u > 1.0+tol)
478 const vector qVec = tVec ^ edge1;
481 const scalar v = (dir & qVec) * inv_det;
483 if (v < -tol || u + v > 1.0+tol)
490 const scalar t = (edge2 & qVec) * inv_det;
492 if (alg == intersection::HALF_RAY && t < -tol)
499 intersection.
setPoint(a_ + u*edge1 + v*edge2);
506 template<
class Po
int,
class Po
intRef>
525 if (d1 <= 0.0 && d2 <= 0.0)
539 if (d3 >= 0.0 && d4 <= d3)
549 scalar vc = d1*d4 - d3*d2;
551 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
553 if ((d1 - d3) < ROOTVSMALL)
562 scalar v = d1/(d1 - d3);
564 point nearPt = a_ + v*ab;
575 if (d6 >= 0.0 && d5 <= d6)
585 scalar vb = d5*d2 - d1*d6;
587 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
589 if ((d2 - d6) < ROOTVSMALL)
598 scalar w = d2/(d2 - d6);
600 point nearPt = a_ + w*ac;
607 scalar va = d3*d6 - d5*d4;
609 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
611 if (((d4 - d3) + (d5 - d6)) < ROOTVSMALL)
621 scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
623 point nearPt = b_ + w*(c_ - b_);
632 if ((va + vb + vc) < ROOTVSMALL)
636 point nearPt = centre();
642 scalar denom = 1.0/(va + vb + vc);
643 scalar v = vb * denom;
644 scalar w = vc * denom;
648 point nearPt = a_ + ab*v + ac*w;
655 template<
class Po
int,
class Po
intRef>
663 label nearLabel = -1;
665 return nearestPointClassify(p, nearType, nearLabel);
669 template<
class Po
int,
class Po
intRef>
677 return nearestPointClassify(p, nearType, nearLabel).hit();
681 template<
class Po
int,
class Po
intRef>
695 intersection::FULL_RAY
735 point nearestEdgePoint;
736 point nearestLinePoint;
757 nearestEdgePoint = triEdgePoint;
758 nearestLinePoint = linePoint;
775 nearestEdgePoint = triEdgePoint;
776 nearestLinePoint = linePoint;
809 template<
class Po
int,
class Po
intRef>
817 is >> t.a_ >> t.b_ >> t.c_;
818 is.readEnd(
"triangle");
820 is.check(
"Istream& operator>>(Istream&, triangle&)");
825 template<
class Po
int,
class Po
intRef>
834 << t.a_ << token::SPACE
835 << t.b_ << token::SPACE
tensor inertia(PointRef refPt=vector::zero, scalar density=1.0) const
Return the inertia tensor, with optional reference.
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 & missPoint() const
Return miss point.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
const Point & c() const
Return third vertex.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
const Point & rawPoint() const
Return point with no checking.
const dimensionedScalar c2
Second radiation constant: default SI units: [m.K].
dimensionedScalar sqrt(const dimensionedScalar &ds)
PointRef end() const
Return second vertex.
dimensionedScalar det(const dimensionedSphericalTensor &dt)
scalar barycentric(const point &pt, List< scalar > &bary) const
Calculate the barycentric coordinates of the given.
bool classify(const point &p, label &nearType, label &nearLabel) const
Classify nearest point to p in triangle plane.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
scalar quality() const
Return quality: Ratio of triangle and circum-circle.
Point randomPoint(Random &rndGen) const
Return a random point on the triangle from a uniform.
scalar sweptVol(const triangle &t) const
Return swept-volume.
Point vec() const
Return start-end vector.
scalar distance() const
Return distance to hit.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().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))
Type sample01()
Return a sample whose components lie in the range 0-1.
void setDistance(const scalar d)
line< point, const point & > linePointRef
Line using referred points.
static const Identity< scalar > I
const Point & a() const
Return first vertex.
Point centre() const
Return centre (centroid)
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.
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 volScalarField & cp
PointRef start() 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.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
A normal distribution model.
const Point & b() const
Return second vertex.
void setSize(const label)
Reset size of List.
Point circumCentre() const
Return circum-centre.
const Point & hitPoint() const
Return hit point.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
dimensioned< scalar > mag(const dimensioned< Type > &)
PointHit< Point > nearestDist(const Point &p) const
Return nearest distance to line from a given point.
bool hit() const
Is there a hit.
PointHit< point > pointHit
scalar circumRadius() const
Return circum-radius.
pointHit intersection(const point &p, const vector &q, const intersection::algorithm alg, const scalar tol=0.0) const
Fast intersection with a ray.
pointHit nearestPoint(const point &p) const
Return nearest point to p on triangle.
void setPoint(const Point &p)
scalar scalar01()
Scalar [0..1] (so including 0,1)
pointHit nearestPointClassify(const point &p, label &nearType, label &nearLabel) const
Find the nearest point to p on the triangle and classify it:
scalar mag() const
Return scalar magnitude.
vector normal() const
Return vector normal.