triangle intersection return value

This commit is contained in:
mattijs 2009-04-09 16:54:35 +01:00
parent b020b28787
commit fa77b7ce77
4 changed files with 10 additions and 17 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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

View File

@ -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.