Skip to content
Snippets Groups Projects
Commit 02f25ea4 authored by Guylaine Prat's avatar Guylaine Prat
Browse files

Upgrade Dunvenhage refining intersection.

Complete Issue 376 resolution, as the solution was not converging in
some cases.
parent fc95ed7b
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,7 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { ...@@ -46,7 +46,7 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm {
/** Nb time cell intersection (with DEM) performed for null intersection: means that infinite loop. /** Nb time cell intersection (with DEM) performed for null intersection: means that infinite loop.
* @since 2.1 */ * @since 2.1 */
private static final int NB_TIME_CELL_INTERSECTION = 1000; private static final int NB_TIME_CELL_INTERSECTION = 100;
/** Cache for DEM tiles. */ /** Cache for DEM tiles. */
private final TilesCache<MinMaxTreeTile> cache; private final TilesCache<MinMaxTreeTile> cache;
...@@ -184,45 +184,59 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { ...@@ -184,45 +184,59 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm {
final Vector3D exitP = ellipsoid.pointAtAltitude(position, los, tile.getMinElevation()); final Vector3D exitP = ellipsoid.pointAtAltitude(position, los, tile.getMinElevation());
final Vector3D entryP = ellipsoid.pointAtAltitude(position, los, tile.getMaxElevation()); final Vector3D entryP = ellipsoid.pointAtAltitude(position, los, tile.getMaxElevation());
final NormalizedGeodeticPoint entry = ellipsoid.transform(entryP, ellipsoid.getBodyFrame(), null, final NormalizedGeodeticPoint entry = ellipsoid.transform(entryP, ellipsoid.getBodyFrame(), null,
tile.getMinimumLongitude()); tile.getMinimumLongitude());
foundIntersection = tile.cellIntersection(entry, ellipsoid.convertLos(entryP, exitP), foundIntersection = tile.cellIntersection(entry, ellipsoid.convertLos(entryP, exitP),
tile.getFloorLatitudeIndex(currentGuess.getLatitude()), tile.getFloorLatitudeIndex(currentGuess.getLatitude()),
tile.getFloorLongitudeIndex(currentGuess.getLongitude())); tile.getFloorLongitudeIndex(currentGuess.getLongitude()));
} else { // with a DEM } else { // with a DEM
final NormalizedGeodeticPoint currentGuess0 = currentGuess;
double deltaS = -1.;
boolean secondChance = false;
while (foundIntersection == null && (nbCall < NB_TIME_CELL_INTERSECTION)) { while (foundIntersection == null && (nbCall < NB_TIME_CELL_INTERSECTION)) {
final Vector3D delta = ellipsoid.transform(currentGuess).subtract(position); final Vector3D delta = ellipsoid.transform(currentGuess).subtract(position);
final double s = Vector3D.dotProduct(delta, los) / los.getNormSq(); final double s = Vector3D.dotProduct(delta, los) / los.getNormSq();
final GeodeticPoint projected = ellipsoid.transform(new Vector3D(1, position, s, los), final GeodeticPoint projected = ellipsoid.transform(new Vector3D(1, position, s, los),
ellipsoid.getBodyFrame(), null); ellipsoid.getBodyFrame(), null);
final NormalizedGeodeticPoint normalizedProjected = final NormalizedGeodeticPoint normalizedProjected =
new NormalizedGeodeticPoint(projected.getLatitude(), new NormalizedGeodeticPoint(projected.getLatitude(),
projected.getLongitude(), projected.getLongitude(),
projected.getAltitude(), projected.getAltitude(),
currentGuess.getLongitude()); currentGuess.getLongitude());
final Tile tile = cache.getTile(normalizedProjected.getLatitude(), normalizedProjected.getLongitude()); final Tile tile = cache.getTile(normalizedProjected.getLatitude(), normalizedProjected.getLongitude());
foundIntersection = tile.cellIntersection(normalizedProjected, foundIntersection = tile.cellIntersection(normalizedProjected,
ellipsoid.convertLos(normalizedProjected, los), ellipsoid.convertLos(normalizedProjected, los),
tile.getFloorLatitudeIndex(normalizedProjected.getLatitude()), tile.getFloorLatitudeIndex(normalizedProjected.getLatitude()),
tile.getFloorLongitudeIndex(normalizedProjected.getLongitude())); tile.getFloorLongitudeIndex(normalizedProjected.getLongitude()));
// For extremely rare case : the cell intersection gave no results ... // For extremely rare case : the cell intersection gave no results ...
// We use as a new guess a slightly modified projected geodetic point (which is on the LOS line) // We use as a new guess a slightly modified projected geodetic point (which is on the LOS line)
if (foundIntersection == null) { if (foundIntersection == null) {
final double shiftedS = s - 1; final double shiftedS = s + deltaS;
final GeodeticPoint currentGuessGP = ellipsoid.transform(new Vector3D(1, position, shiftedS, los), final GeodeticPoint currentGuessGP = ellipsoid.transform(new Vector3D(1, position, shiftedS, los),
ellipsoid.getBodyFrame(), null); ellipsoid.getBodyFrame(), null);
currentGuess = new NormalizedGeodeticPoint(currentGuessGP.getLatitude(), currentGuess = new NormalizedGeodeticPoint(currentGuessGP.getLatitude(),
currentGuessGP.getLongitude(), currentGuessGP.getLongitude(),
currentGuessGP.getAltitude(), currentGuessGP.getAltitude(),
projected.getLongitude()); projected.getLongitude());
// to avoid infinite loop ... // to avoid infinite loop ...
nbCall++; nbCall++;
}
// if impossible to find a solution with deltaS = -1
// we start a new search with deltaS = +1
if (nbCall == NB_TIME_CELL_INTERSECTION && !secondChance) {
currentGuess = currentGuess0;
deltaS = 1.;
nbCall = 0;
secondChance = true; // to avoid infinite loop if second chance does not work !
} // end if nbCall == NB_TIME_CELL_INTERSECTION
} // end if foundIntersection = null
} // end while foundIntersection = null } // end while foundIntersection = null
} // end test on flatbody } // end test on flatbody
return foundIntersection; return foundIntersection;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment