#3387 Add epsilon to handle singularities in OffshoreSphericalCoords

This commit is contained in:
Jacob Støren
2018-09-26 12:32:38 +02:00
parent c6cdbf9436
commit 170da81287

View File

@@ -24,21 +24,23 @@
// Y - North, X - East, Z - up but depth is negative Z
// azi is measured from the Northing (Y) Axis in Clockwise direction looking down
// inc is measured from the negative Z (depth) axis
const double singularityEpsilon = 1.0e-5;
class RiaOffshoreSphericalCoords
{
public:
explicit RiaOffshoreSphericalCoords(const cvf::Vec3f& vec)
{
// Azimuth:
if (vec[0] == 0.0f && vec[1] == 0.0 ) incAziR[1] = 0.0f;
if ( fabs(vec[0]) < singularityEpsilon && fabs(vec[1]) < singularityEpsilon ) incAziR[1] = 0.0f;
else incAziR[1] = atan2(vec[0], vec[1]); // atan2(Y, X)
// R
incAziR[2] = vec.length();
// Inclination from vertical down
if (incAziR[2] == 0) incAziR[0] = 0.0f;
if (fabs( incAziR[2]) < singularityEpsilon) incAziR[0] = 0.0f;
else incAziR[0] = acos(-vec[2]/incAziR[2]);
}
@@ -46,14 +48,14 @@ public:
explicit RiaOffshoreSphericalCoords(const cvf::Vec3d& vec)
{
// Azimuth:
if (vec[0] == 0.0 && vec[1] == 0.0 ) incAziR[1] = 0.0;
if (fabs(vec[0]) < singularityEpsilon && fabs(vec[1]) < singularityEpsilon ) incAziR[1] = 0.0;
else incAziR[1] = atan2(vec[0], vec[1]); // atan2(Y, X)
// R
incAziR[2] = vec.length();
// Inclination from vertical down
if (incAziR[2] == 0) incAziR[0] = 0.0;
if (fabs( incAziR[2]) < singularityEpsilon) incAziR[0] = 0.0;
else incAziR[0] = acos(-vec[2]/incAziR[2]);
}