triIntersect: Stabilise source-point-to-target-triangle projections

This commit is contained in:
Will Bainbridge
2023-12-21 10:37:03 +00:00
parent f9b4027b05
commit 705a4999bd

View File

@ -1251,11 +1251,33 @@ Foam::barycentric2D Foam::triIntersect::srcPointTgtTriIntersection
const scalar maxMagDetAY = mag(detAY[findMax(cmptMag(detAY))]);
const vector y =
vector y =
maxMagDetAY/vGreat < mag(detA)
? detAY/detA
: detAY/maxMagDetAY*vGreat;
// Project into the source triangle
if (cmptMin(y) < 0)
{
const direction iMin = findMin(y);
const direction iMax = findMax(y);
const direction iMid = 3 - iMin - iMax;
if (y[iMid] < 0)
{
y[iMin] = 0;
y[iMax] = 1;
y[iMid] = 0;
}
else
{
const scalar t = y[iMax] + y[iMid];
y[iMin] = 0;
y[iMax] /= t;
y[iMid] /= t;
}
}
return barycentric2D(y.x(), y.y(), y.z());
}