mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3387 Add epsilon to handle singularities in OffshoreSphericalCoords
This commit is contained in:
@@ -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]);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user