Commit fa77b7ce authored by mattijs's avatar mattijs
Browse files

triangle intersection return value

parent b020b287
......@@ -166,8 +166,8 @@ public:
const intersection::direction dir = intersection::VECTOR
) const;
//- Fast intersection with a ray. Distance is normal distance
// to the intersection.
//- Fast intersection with a ray. Distance is normalised distance
// to the intersection (normalised with the vector magnitude).
// For a hit, the distance is signed. Positive number
// represents the point in front of triangle. In case of miss
// pointHit position is undefined.
......
......@@ -73,7 +73,7 @@ Foam::scalar Foam::ExactParticle<ParticleType>::trackToFace
const labelList& cFaces = mesh.cells()[this->celli_];
point intersection(vector::zero);
scalar distanceSqr = VGREAT;
scalar trackFraction = VGREAT;
label hitFacei = -1;
const vector vec = endPosition-this->position_;
......@@ -93,16 +93,11 @@ Foam::scalar Foam::ExactParticle<ParticleType>::trackToFace
intersection::HALF_RAY
);
if (inter.hit())
if (inter.hit() && inter.distance() < trackFraction)
{
scalar s = magSqr(inter.hitPoint()-this->position_);
if (s < distanceSqr)
{
distanceSqr = s;
hitFacei = facei;
intersection = inter.hitPoint();
}
trackFraction = inter.distance();
hitFacei = facei;
intersection = inter.hitPoint();
}
}
}
......@@ -118,12 +113,10 @@ Foam::scalar Foam::ExactParticle<ParticleType>::trackToFace
);
}
scalar trackFraction = Foam::sqrt(distanceSqr/magSqr(vec));
if (trackFraction >= (1.0-SMALL))
{
// Nearest intersection beyond endPosition so we hit endPosition.
trackFraction = 1.0;
this->position_ = endPosition;
this->facei_ = -1;
return 1.0;
......
......@@ -528,7 +528,7 @@ bool Foam::treeDataFace::intersects
intersection::HALF_RAY
);
if (inter.hit() && magSqr(inter.hitPoint()-start) <= magSqr(dir))
if (inter.hit() && inter.distance() <= 1)
{
// Note: no extra test on whether intersection is in front of us
// since using half_ray
......
......@@ -456,7 +456,7 @@ bool Foam::treeDataTriSurface::intersects
indexedOctree<treeDataTriSurface>::perturbTol()
);
if (inter.hit() && magSqr(inter.hitPoint()-start) <= magSqr(dir))
if (inter.hit() && inter.distance() <= 1)
{
// Note: no extra test on whether intersection is in front of us
// since using half_ray.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment