From 28c24ec27ca39f171f7b31506c8f4db4d27b7f54 Mon Sep 17 00:00:00 2001
From: Luc Maisonobe <luc@orekit.org>
Date: Fri, 26 Sep 2014 11:45:39 +0200
Subject: [PATCH] =?UTF-8?q?Attempt=20to=20fix=20=C2=B1=CF=80=20longitude?=
 =?UTF-8?q?=20discontinuity.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../rugged/intersection/duvenhage/DuvenhageAlgorithm.java  | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java b/core/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java
index 2d1b03cd..ac359e18 100644
--- a/core/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java
+++ b/core/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java
@@ -18,6 +18,7 @@ package org.orekit.rugged.intersection.duvenhage;
 
 import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.math3.util.FastMath;
+import org.apache.commons.math3.util.MathUtils;
 import org.orekit.bodies.GeodeticPoint;
 import org.orekit.errors.OrekitException;
 import org.orekit.rugged.api.RuggedException;
@@ -384,7 +385,11 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm {
         final Vector3D exitP = ellipsoid.pointAtAltitude(position, los, tile.getMinElevation() - STEP);
         final GeodeticPoint exitGP = ellipsoid.transform(exitP, ellipsoid.getBodyFrame(), null);
 
-        switch (tile.getLocation(exitGP.getLatitude(), exitGP.getLongitude())) {
+        // fix longitude discontinuity
+        final double meanTileLongitude = tile.getLongitudeAtIndex(tile.getLongitudeColumns() / 2);
+        final double fixedLongitude    = MathUtils.normalizeAngle(exitGP.getLongitude(), meanTileLongitude);
+
+        switch (tile.getLocation(exitGP.getLatitude(), fixedLongitude)) {
         case SOUTH_WEST :
             return new LimitPoint(ellipsoid,
                                   selectClosest(ellipsoid.pointAtLatitude(position,  los, tile.getMinimumLatitude(), exitP),
-- 
GitLab