From c548c4a12bd34c4f6f33b3ba77aba01dc429cb77 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 25 May 2020 20:43:59 +0200 Subject: [PATCH] #5899 Fracture: Use robust way to find diff between two angles --- .../Completions/RimFracture.cpp | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Completions/RimFracture.cpp b/ApplicationCode/ProjectDataModel/Completions/RimFracture.cpp index edaa39c45e..ec79ce4c12 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimFracture.cpp +++ b/ApplicationCode/ProjectDataModel/Completions/RimFracture.cpp @@ -381,13 +381,29 @@ double RimFracture::endMD() const } } +//-------------------------------------------------------------------------------------------------- +/// https://stackoverflow.com/a/52432897 +//-------------------------------------------------------------------------------------------------- +double getAbsoluteDiff2Angles( const double x, const double y, const double c ) +{ + // c can be PI (for radians) or 180.0 (for degrees); + return c - fabs( fmod( fabs( x - y ), 2 * c ) - c ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- double RimFracture::wellFractureAzimuthDiff() const { - double wellDifference = fabs( wellAzimuthAtFracturePosition() - m_azimuth ); - return wellDifference; + // Compute the relative difference between two lines + // See https://github.com/OPM/ResInsight/issues/5899 + + double angle1 = wellAzimuthAtFracturePosition(); + double angle2 = m_azimuth; + + double smallestDiffDegrees = getAbsoluteDiff2Angles( angle1, angle2, 180.0 ); + + return smallestDiffDegrees; } //-------------------------------------------------------------------------------------------------- @@ -399,6 +415,9 @@ QString RimFracture::wellFractureAzimuthDiffText() const return QString::number( wellDifference, 'f', 2 ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- QString RimFracture::wellAzimuthAtFracturePositionText() const { double wellAzimuth = wellAzimuthAtFracturePosition();