Use more accurate version of inside cutoff planes.

This commit is contained in:
Karl Wright 2016-04-27 20:09:06 -04:00
parent 31f3d1f209
commit 5545e9edf1
2 changed files with 52 additions and 6 deletions

View File

@ -865,8 +865,10 @@ class GeoComplexPolygon extends GeoBasePolygon {
this.testPointCutoffPlane = new SidedPlane(thePoint, testPointPlane, testPoint);
this.checkPointCutoffPlane = new SidedPlane(testPoint, travelPlane, thePoint);
this.testPointOtherCutoffPlane = new SidedPlane(testPoint, travelPlane, -(travelPlane.x * intersectionPoint.x + travelPlane.y * intersectionPoint.y + travelPlane.z * intersectionPoint.z));
this.checkPointOtherCutoffPlane = new SidedPlane(thePoint, testPointPlane, -(testPointPlane.x * intersectionPoint.x + testPointPlane.y * intersectionPoint.y + testPointPlane.z * intersectionPoint.z));
// Convert travel plane to a sided plane
this.testPointOtherCutoffPlane = new SidedPlane(testPoint, travelPlane, travelPlane.D);
// Convert testPoint plane to a sided plane
this.checkPointOtherCutoffPlane = new SidedPlane(thePoint, testPointPlane, testPointPlane.D);
// Figure out which of the above/below planes are inside vs. outside. To do this,
// we look for the point that is within the bounds of the testPointPlane and travelPlane. The two sides that intersected there are the inside
@ -881,8 +883,8 @@ class GeoComplexPolygon extends GeoBasePolygon {
assert belowBelow != null : "Below + below should not be coplanar";
final GeoPoint[] belowAbove = travelBelowPlane.findIntersections(planetModel, testPointAbovePlane, testPointCutoffPlane, testPointOtherCutoffPlane, checkPointCutoffPlane, checkPointOtherCutoffPlane);
assert belowAbove != null : "Below + above should not be coplanar";
assert aboveAbove.length + aboveBelow.length + belowBelow.length + belowAbove.length == 1 : "Can be exactly one inside point, instead was: aa="+aboveAbove.length+" ab=" + aboveBelow.length+" bb="+ belowBelow.length+" ba=" + belowAbove.length;
assert ((aboveAbove.length > 0)?1:0) + ((aboveBelow.length > 0)?1:0) + ((belowBelow.length > 0)?1:0) + ((belowAbove.length > 0)?1:0) == 1 : "Can be exactly one inside point, instead was: aa="+aboveAbove.length+" ab=" + aboveBelow.length+" bb="+ belowBelow.length+" ba=" + belowAbove.length;
final GeoPoint insideIntersection;
if (aboveAbove.length > 0) {
@ -911,8 +913,8 @@ class GeoComplexPolygon extends GeoBasePolygon {
insideIntersection = belowAbove[0];
}
insideTravelCutoffPlane = new SidedPlane(thePoint, travelInsidePlane, insideIntersection);
insideTestPointCutoffPlane = new SidedPlane(testPoint, testPointInsidePlane, insideIntersection);
insideTravelCutoffPlane = new SidedPlane(thePoint, testPointInsidePlane, testPointInsidePlane.D);
insideTestPointCutoffPlane = new SidedPlane(testPoint, travelInsidePlane, travelInsidePlane.D);
}

View File

@ -134,6 +134,12 @@ public class GeoPolygonTest {
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.5);
assertTrue(c.isWithin(gp));
shapes = new ArrayList<>();
shapes.add(new GeoPolygonFactory.PolygonDescription(points));
c = GeoPolygonFactory.makeLargeGeoPolygon(PlanetModel.SPHERE, shapes);
assertTrue(c.isWithin(gp));
}
@Test
@ -141,6 +147,7 @@ public class GeoPolygonTest {
GeoPolygon c;
GeoPoint gp;
List<GeoPoint> points;
List<GeoPolygonFactory.PolygonDescription> shapes;
points = new ArrayList<GeoPoint>();
points.add(new GeoPoint(PlanetModel.SPHERE, 0.0, -0.4));
@ -177,6 +184,43 @@ public class GeoPolygonTest {
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI);
assertFalse(c.isWithin(gp));
// Now, same thing for large polygon
shapes = new ArrayList<>();
shapes.add(new GeoPolygonFactory.PolygonDescription(points));
c = GeoPolygonFactory.makeLargeGeoPolygon(PlanetModel.SPHERE, shapes);
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.65);
assertFalse(c.isWithin(gp)); //??? fails
// Sample some points within
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.45);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.5);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.55);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, -0.05, -0.5);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.05, -0.5);
assertTrue(c.isWithin(gp));
// Sample some nearby points outside
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.65);
assertFalse(c.isWithin(gp)); //??? fails
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.35);
assertFalse(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, -0.15, -0.5);
assertFalse(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.15, -0.5);
assertFalse(c.isWithin(gp));
// Random points outside
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, 0.0);
assertFalse(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, Math.PI * 0.5, 0.0);
assertFalse(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI);
assertFalse(c.isWithin(gp));
// Next bunch of small polygon points
points = new ArrayList<GeoPoint>();
points.add(new GeoPoint(PlanetModel.SPHERE, 0.0, -0.4));
points.add(new GeoPoint(PlanetModel.SPHERE, 0.1, -0.5));