From 39ba3e8734ea1c3dd17a232072b26d1f82c4ac69 Mon Sep 17 00:00:00 2001
From: Luc Maisonobe <luc@orekit.org>
Date: Thu, 16 Jul 2015 10:17:42 +0200
Subject: [PATCH] New test and simplified code.

---
 .../utils/RoughVisibilityEstimator.java       | 17 +++++------
 .../utils/RoughVisibilityEstimatorTest.java   | 28 +++++++++++++++++++
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/orekit/rugged/utils/RoughVisibilityEstimator.java b/src/main/java/org/orekit/rugged/utils/RoughVisibilityEstimator.java
index cfd7d055..8c0dbbb9 100644
--- a/src/main/java/org/orekit/rugged/utils/RoughVisibilityEstimator.java
+++ b/src/main/java/org/orekit/rugged/utils/RoughVisibilityEstimator.java
@@ -110,8 +110,8 @@ public class RoughVisibilityEstimator {
         final Vector3D point = ellipsoid.transform(groundPoint);
         int closeIndex = findClose(last, point);
 
-        // check if there are closer points in previous half periods
-        final int repeat = (int) FastMath.rint(FastMath.PI / rateVSIndices);
+        // check if there are closer points in previous periods
+        final int repeat = (int) FastMath.rint(2.0 * FastMath.PI / rateVSIndices);
         for (int index = closeIndex - repeat; index > 0; index -= repeat) {
             final int otherIndex = findClose(index, point);
             if (otherIndex != closeIndex &&
@@ -121,7 +121,7 @@ public class RoughVisibilityEstimator {
             }
         }
 
-        // check if there are closer points in next half periods
+        // check if there are closer points in next periods
         for (int index = closeIndex + repeat; index < pvGround.size(); index += repeat) {
             final int otherIndex = findClose(index, point);
             if (otherIndex != closeIndex &&
@@ -160,6 +160,10 @@ public class RoughVisibilityEstimator {
     }
 
     /** Estimate angular motion needed to go past test point.
+     * <p>
+     * This estimation is quite crude. The sub-satellite point is properly on the
+     * ellipsoid surface, but we compute the angle assuming a spherical shape.
+     * </p>
      * @param subSatellite current sub-satellite position-velocity
      * @param point test point
      * @return angular motion to go past test point (positive is
@@ -170,12 +174,9 @@ public class RoughVisibilityEstimator {
 
         final Vector3D ssP      = subSatellite.getPosition();
         final Vector3D momentum = subSatellite.getMomentum();
+        final double   y        = Vector3D.dotProduct(point, Vector3D.crossProduct(momentum, ssP).normalize());
+        final double   x        = Vector3D.dotProduct(point, ssP.normalize());
 
-        // find phase angle around momentum
-        final Vector3D yAxis = Vector3D.crossProduct(momentum, ssP).normalize();
-        final Vector3D xAxis = Vector3D.crossProduct(yAxis, momentum).normalize();
-        final double   y     = Vector3D.dotProduct(point, yAxis);
-        final double   x     = Vector3D.dotProduct(point, xAxis);
         return FastMath.atan2(y, x);
 
     }
diff --git a/src/test/java/org/orekit/rugged/utils/RoughVisibilityEstimatorTest.java b/src/test/java/org/orekit/rugged/utils/RoughVisibilityEstimatorTest.java
index 2245083c..5858bf5d 100644
--- a/src/test/java/org/orekit/rugged/utils/RoughVisibilityEstimatorTest.java
+++ b/src/test/java/org/orekit/rugged/utils/RoughVisibilityEstimatorTest.java
@@ -88,6 +88,34 @@ public class RoughVisibilityEstimatorTest {
 
     }
 
+    @Test
+    public void testOneOrbitsSpan()
+        throws RuggedException, OrekitException, URISyntaxException {
+
+        String path = getClass().getClassLoader().getResource("orekit-data").toURI().getPath();
+        DataProvidersManager.getInstance().addProvider(new DirectoryCrawler(new File(path)));
+        BodyShape  earth                                  = createEarth();
+        NormalizedSphericalHarmonicsProvider gravityField = createGravityField();
+        Orbit      orbit                                  = createOrbit(gravityField.getMu());
+        Propagator propagator                             = createPropagator(earth, gravityField, orbit);
+        final List<TimeStampedPVCoordinates> pv = new ArrayList<TimeStampedPVCoordinates>();
+        propagator.setMasterMode(1.0, new OrekitFixedStepHandler() {
+            public void init(SpacecraftState s0, AbsoluteDate t) {
+            }
+            public void handleStep(SpacecraftState currentState, boolean isLast) {
+                pv.add(currentState.getPVCoordinates());
+            }
+        });
+        propagator.propagate(orbit.getDate().shiftedBy(orbit.getKeplerianPeriod()));
+
+        RoughVisibilityEstimator estimator = new RoughVisibilityEstimator(ellipsoid, orbit.getFrame(), pv);
+        AbsoluteDate d = estimator.estimateVisibility(new GeodeticPoint(FastMath.toRadians(43.303),
+                                                                        FastMath.toRadians(-46.126),
+                                                                        0.0));
+        Assert.assertEquals("2012-01-01T01:02:39.123", d.toString(TimeScalesFactory.getUTC()));
+
+    }
+
     private BodyShape createEarth()
                     throws OrekitException {
         return new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
-- 
GitLab