Skip to content

Commit

Permalink
LUCENE-8363: Interpolate should yield points on the ellipsoid.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaddyWri committed Jun 19, 2018
1 parent 63d7f5d commit e27cf65
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public Edge(final PlanetModel pm, final GeoPoint startPoint, final GeoPoint endP
this.plane = new Plane(startPoint, endPoint);
this.startPlane = new SidedPlane(endPoint, plane, startPoint);
this.endPlane = new SidedPlane(startPoint, plane, endPoint);
final GeoPoint interpolationPoint = plane.interpolate(startPoint, endPoint, halfProportions)[0];
final GeoPoint interpolationPoint = plane.interpolate(pm, startPoint, endPoint, halfProportions)[0];
this.backingPlane = new SidedPlane(interpolationPoint, interpolationPoint, 0.0);
this.planeBounds = new XYZBounds();
this.planeBounds.addPoint(startPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,13 @@ public double linearDistanceSquared(final PlanetModel planetModel, final double
* Find points on the boundary of the intersection of a plane and the unit sphere,
* given a starting point, and ending point, and a list of proportions of the arc (e.g. 0.25, 0.5, 0.75).
* The angle between the starting point and ending point is assumed to be less than pi.
* @param planetModel is the planet model.
* @param start is the start point.
* @param end is the end point.
* @param proportions is an array of fractional proportions measured between start and end.
* @return an array of points corresponding to the proportions passed in.
*/
public GeoPoint[] interpolate(final GeoPoint start, final GeoPoint end, final double[] proportions) {
public GeoPoint[] interpolate(final PlanetModel planetModel, final GeoPoint start, final GeoPoint end, final double[] proportions) {
// Steps:
// (1) Translate (x0,y0,z0) of endpoints into origin-centered place:
// x1 = x0 + D*A
Expand Down Expand Up @@ -595,7 +596,7 @@ public GeoPoint[] interpolate(final GeoPoint start, final GeoPoint end, final do
final double sinNewAngle = Math.sin(newAngle);
final double cosNewAngle = Math.cos(newAngle);
final Vector newVector = new Vector(cosNewAngle * startMagnitude, sinNewAngle * startMagnitude, 0.0);
returnValues[i] = reverseModify(newVector, transX, transY, transZ, sinRA, cosRA, sinHA, cosHA);
returnValues[i] = reverseModify(planetModel, newVector, transX, transY, transZ, sinRA, cosRA, sinHA, cosHA);
}

return returnValues;
Expand All @@ -620,6 +621,7 @@ protected static Vector modify(final GeoPoint start, final double transX, final

/**
* Reverse modify a point to produce a GeoPoint in normal space.
* @param planetModel is the planet model.
* @param point is the translated point.
* @param transX is the translation x value.
* @param transY is the translation y value.
Expand All @@ -630,10 +632,11 @@ protected static Vector modify(final GeoPoint start, final double transX, final
* @param cosHA is the cosine of the height angle.
* @return the original point.
*/
protected static GeoPoint reverseModify(final Vector point, final double transX, final double transY, final double transZ,
final double sinRA, final double cosRA, final double sinHA, final double cosHA) {
protected static GeoPoint reverseModify(final PlanetModel planetModel,
final Vector point, final double transX, final double transY, final double transZ,
final double sinRA, final double cosRA, final double sinHA, final double cosHA) {
final Vector result = point.rotateXZ(-sinHA, cosHA).rotateXY(-sinRA, cosRA).translate(-transX, -transY, -transZ);
return new GeoPoint(result.x, result.y, result.z);
return planetModel.createSurfacePoint(result.x, result.y, result.z);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testInterpolation() {
// [A=-0.6135342247741855, B=0.21504338363863665, C=0.28188192383666794, D=0.0, side=-1.0] internal? false;
final Plane p = new Plane(-0.6135342247741855, 0.21504338363863665, 0.28188192383666794, 0.0);

final GeoPoint[] points = p.interpolate(start, end, new double[]{0.25, 0.50, 0.75});
final GeoPoint[] points = p.interpolate(PlanetModel.SPHERE, start, end, new double[]{0.25, 0.50, 0.75});

for (GeoPoint point : points) {
assertTrue(p.evaluateIsZero(point));
Expand Down

0 comments on commit e27cf65

Please sign in to comment.