Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A2ABB200D4D for ; Sun, 3 Dec 2017 10:29:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id A12C4160C0B; Sun, 3 Dec 2017 09:29:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C0055160BF1 for ; Sun, 3 Dec 2017 10:29:50 +0100 (CET) Received: (qmail 52031 invoked by uid 500); 3 Dec 2017 09:29:49 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 52022 invoked by uid 99); 3 Dec 2017 09:29:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Dec 2017 09:29:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C6F8EE0219; Sun, 3 Dec 2017 09:29:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: kwright@apache.org To: commits@lucene.apache.org Message-Id: <794067be5cda4c9bafb5e9899b0dcdf8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: lucene-solr:branch_7x: LUCENE-8076: It is possible to create planet models that are not normalized and this messes up surface distance computations. Therefore, normalize these computations. Committed on behalf of Ignacio Vera. Date: Sun, 3 Dec 2017 09:29:49 +0000 (UTC) archived-at: Sun, 03 Dec 2017 09:29:51 -0000 Repository: lucene-solr Updated Branches: refs/heads/branch_7x 62b350067 -> 047672bbe LUCENE-8076: It is possible to create planet models that are not normalized and this messes up surface distance computations. Therefore, normalize these computations. Committed on behalf of Ignacio Vera. Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/047672bb Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/047672bb Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/047672bb Branch: refs/heads/branch_7x Commit: 047672bbe88de5cb45b622069b09ac58a0d8e0d2 Parents: 62b3500 Author: Karl Wright Authored: Sun Dec 3 04:27:51 2017 -0500 Committer: Karl Wright Committed: Sun Dec 3 04:29:44 2017 -0500 ---------------------------------------------------------------------- .../lucene/spatial3d/geom/PlanetModel.java | 17 ++++++++----- .../spatial3d/geom/GeoExactCircleTest.java | 25 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/047672bb/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java ---------------------------------------------------------------------- diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java index 37297d3..2aabfc1 100644 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java @@ -60,7 +60,12 @@ public class PlanetModel implements SerializableObject { public final double flattening; /** The square ratio */ public final double squareRatio; - + /** The scale of the planet */ + public final double scale; + /** The inverse of scale */ + public final double inverseScale; + + // We do NOT include radius, because all computations in geo3d are in radians, not meters. // Compute north and south pole for planet model, since these are commonly used. @@ -99,6 +104,8 @@ public class PlanetModel implements SerializableObject { this.MAX_X_POLE = new GeoPoint(ab, 1.0, 0.0, 0.0, 0.0, 0.0); this.MIN_Y_POLE = new GeoPoint(ab, 0.0, -1.0, 0.0, 0.0, -Math.PI * 0.5); this.MAX_Y_POLE = new GeoPoint(ab, 0.0, 1.0, 0.0, 0.0, Math.PI * 0.5); + this.scale = (2.0 * ab + c)/3.0; + this.inverseScale = 1.0 / scale; this.minimumPoleDistance = Math.min(surfaceDistance(NORTH_POLE, SOUTH_POLE), surfaceDistance(MIN_X_POLE, MAX_X_POLE)); } @@ -315,14 +322,13 @@ public class PlanetModel implements SerializableObject { lambda = L + (1.0 - C) * flattening * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1.0 + 2.0 * cos2SigmaM *cos2SigmaM))); } while (Math.abs(lambda-lambdaP) >= Vector.MINIMUM_RESOLUTION && ++iterLimit < 100); - final double uSq = cosSqAlpha * this.squareRatio; final double A = 1.0 + uSq / 16384.0 * (4096.0 + uSq * (-768.0 + uSq * (320.0 - 175.0 * uSq))); final double B = uSq / 1024.0 * (256.0 + uSq * (-128.0 + uSq * (74.0 - 47.0 * uSq))); final double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4.0 * (cosSigma * (-1.0 + 2.0 * cos2SigmaM * cos2SigmaM)- B / 6.0 * cos2SigmaM * (-3.0 + 4.0 * sinSigma * sinSigma) * (-3.0 + 4.0 * cos2SigmaM * cos2SigmaM))); - return c * A * (sigma - deltaSigma); + return c * inverseScale * A * (sigma - deltaSigma); } /** Compute new point given original point, a bearing direction, and an adjusted angle (as would be computed by @@ -360,7 +366,7 @@ public class PlanetModel implements SerializableObject { double cosσ; double Δσ; - double σ = dist / (c * A); + double σ = dist / (c * inverseScale * A); double σʹ; double iterations = 0; do { @@ -370,9 +376,8 @@ public class PlanetModel implements SerializableObject { Δσ = B * sinσ * (cos2σM + B / 4.0 * (cosσ * (-1.0 + 2.0 * cos2σM * cos2σM) - B / 6.0 * cos2σM * (-3.0 + 4.0 * sinσ * sinσ) * (-3.0 + 4.0 * cos2σM * cos2σM))); σʹ = σ; - σ = dist / (c * A) + Δσ; + σ = dist / (c * inverseScale * A) + Δσ; } while (Math.abs(σ - σʹ) >= Vector.MINIMUM_RESOLUTION && ++iterations < 100); - double x = sinU1 * sinσ - cosU1 * cosσ * cosα1; double φ2 = Math.atan2(sinU1 * cosσ + cosU1 * sinσ * cosα1, (1.0 - flattening) * Math.sqrt(sinα * sinα + x * x)); double λ = Math.atan2(sinσ * sinα1, cosU1 * cosσ - sinU1 * sinσ * cosα1); http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/047672bb/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoExactCircleTest.java ---------------------------------------------------------------------- diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoExactCircleTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoExactCircleTest.java index 859cded..2f758f1 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoExactCircleTest.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoExactCircleTest.java @@ -53,6 +53,31 @@ public class GeoExactCircleTest extends RandomGeo3dShapeGenerator{ } @Test + public void testSurfacePointOnBearingScale(){ + double ab = 1.6; + double c = 0.7; + PlanetModel p1 = PlanetModel.WGS84; + PlanetModel p2 = new PlanetModel(0.5 * PlanetModel.WGS84.ab, 0.5 * PlanetModel.WGS84.c ); + GeoPoint point1P1 = new GeoPoint(p1, 0, 0); + GeoPoint point2P1 = new GeoPoint(p1, 1, 1); + GeoPoint point1P2 = new GeoPoint(p2, point1P1.getLatitude(), point1P1.getLongitude()); + GeoPoint point2P2 = new GeoPoint(p2, point2P1.getLatitude(), point2P1.getLongitude()); + + double dist = 0.2* Math.PI; + double bearing = 0.2 * Math.PI; + + GeoPoint new1 = p1.surfacePointOnBearing(point2P1, dist, bearing); + GeoPoint new2 = p2.surfacePointOnBearing(point2P2, dist, bearing); + + assertEquals(new1.getLatitude(), new2.getLatitude(), 1e-12); + assertEquals(new1.getLongitude(), new2.getLongitude(), 1e-12); + //This is true if surfaceDistance return results always in radians + double d1 = p1.surfaceDistance(point1P1, point2P1); + double d2 = p2.surfaceDistance(point1P2, point2P2); + assertEquals(d1, d2, 1e-12); + } + + @Test @Repeat(iterations = 100) public void RandomPointBearingWGS84Test(){ PlanetModel planetModel = PlanetModel.WGS84;