/** Compute a GeoPoint that's scaled to actually be on the planet surface. * @param vector is the vector. * @return the scaled point. */ public GeoPoint createSurfacePoint(final Vector vector) { return createSurfacePoint(vector.x, vector.y, vector.z); }
/** Read a PlanetObject from a stream. * @param inputStream is the input stream. * @return the PlanetObject. */ public static PlanetObject readPlanetObject(final InputStream inputStream) throws IOException { final PlanetModel pm = new PlanetModel(inputStream); final SerializableObject so = readObject(pm, inputStream); if (!(so instanceof PlanetObject)) { throw new IOException("Type of object is not expected PlanetObject: "+so.getClass().getName()); } return (PlanetObject)so; }
@Override public Bounds noBound(final PlanetModel planetModel) { minX = planetModel.getMinimumXValue(); maxX = planetModel.getMaximumXValue(); minY = planetModel.getMinimumYValue(); maxY = planetModel.getMaximumYValue(); minZ = planetModel.getMinimumZValue(); maxZ = planetModel.getMaximumZValue(); return this; }
private static int encodeY(final double y) { if (y > PlanetModel.WGS84.getMaximumYValue()) { throw new IllegalArgumentException("y value exceeds WGS84 maximum"); } else if (y < PlanetModel.WGS84.getMinimumYValue()) { throw new IllegalArgumentException("y value less than WGS84 minimum"); } return (int)Math.floor((y - PlanetModel.WGS84.getMinimumYValue()) * yFactor + 0.5); }
private static int encodeX(final double x) { if (x > PlanetModel.WGS84.getMaximumXValue()) { throw new IllegalArgumentException("x value exceeds WGS84 maximum"); } else if (x < PlanetModel.WGS84.getMinimumXValue()) { throw new IllegalArgumentException("x value less than WGS84 minimum"); } return (int)Math.floor((x - PlanetModel.WGS84.getMinimumXValue()) * xFactor + 0.5); }
/** Constructor. * @param ab is the x/y scaling factor. * @param c is the z scaling factor. */ public PlanetModel(final double ab, final double c) { this.ab = ab; this.c = c; this.inverseAb = 1.0 / ab; this.inverseC = 1.0 / c; this.flattening = (ab - c) * inverseAb; this.squareRatio = (ab * ab - c * c) / (c * c); this.inverseAbSquared = inverseAb * inverseAb; this.inverseCSquared = inverseC * inverseC; this.NORTH_POLE = new GeoPoint(c, 0.0, 0.0, 1.0, Math.PI * 0.5, 0.0); this.SOUTH_POLE = new GeoPoint(c, 0.0, 0.0, -1.0, -Math.PI * 0.5, 0.0); this.MIN_X_POLE = new GeoPoint(ab, -1.0, 0.0, 0.0, 0.0, -Math.PI); 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)); }
this.maxZ = maxZ; final double worldMinX = planetModel.getMinimumXValue(); final double worldMaxX = planetModel.getMaximumXValue(); final boolean XminYminZ = planetModel.pointOutside(X, minY, minZ); final boolean XminYmaxZ = planetModel.pointOutside(X, minY, maxZ); final boolean XmaxYminZ = planetModel.pointOutside(X, maxY, minZ); final boolean XmaxYmaxZ = planetModel.pointOutside(X, maxY, maxZ);
this.maxZ = maxZ; final double worldMinY = planetModel.getMinimumYValue(); final double worldMaxY = planetModel.getMaximumYValue(); final boolean minXYminZ = planetModel.pointOutside(minX, Y, minZ); final boolean minXYmaxZ = planetModel.pointOutside(minX, Y, maxZ); final boolean maxXYminZ = planetModel.pointOutside(maxX, Y, minZ); final boolean maxXYmaxZ = planetModel.pointOutside(maxX, Y, maxZ);
this.Z = Z; final double worldMinZ = planetModel.getMinimumZValue(); final double worldMaxZ = planetModel.getMaximumZValue(); final boolean minXminYZ = planetModel.pointOutside(minX, minY, Z); final boolean minXmaxYZ = planetModel.pointOutside(minX, maxY, Z); final boolean maxXminYZ = planetModel.pointOutside(maxX, minY, Z); final boolean maxXmaxYZ = planetModel.pointOutside(maxX, maxY, Z);
final GeoPoint northPoint = planetModel.surfacePointOnBearing(center, radius, 0.0); final GeoPoint southPoint = planetModel.surfacePointOnBearing(center, radius, Math.PI); final GeoPoint eastPoint = planetModel.surfacePointOnBearing(center, radius, Math.PI * 0.5); final GeoPoint westPoint = planetModel.surfacePointOnBearing(center, radius, Math.PI * 1.5); final GeoPoint interpPoint1 = planetModel.surfacePointOnBearing(center, radius, interpPoint1Bearing); final double interpPoint2Bearing = (thisSlice.point2Bearing + thisSlice.middlePointBearing) * 0.5; final GeoPoint interpPoint2 = planetModel.surfacePointOnBearing(center, radius, interpPoint2Bearing);
private static int encodeZ(final double z) { if (z > PlanetModel.WGS84.getMaximumZValue()) { throw new IllegalArgumentException("z value exceeds WGS84 maximum"); } else if (z < PlanetModel.WGS84.getMinimumZValue()) { throw new IllegalArgumentException("z value less than WGS84 minimum"); } return (int)Math.floor((z - PlanetModel.WGS84.getMinimumZValue()) * zFactor + 0.5); }
/** Return true if minX is as small as the planet model allows. *@return true if minX has reached its bound. */ public boolean isSmallestMinX(final PlanetModel planetModel) { if (minX == null) return false; return minX - planetModel.getMinimumXValue() < Vector.MINIMUM_RESOLUTION; }
/** Return true if maxX is as large as the planet model allows. *@return true if maxX has reached its bound. */ public boolean isLargestMaxX(final PlanetModel planetModel) { if (maxX == null) return false; return planetModel.getMaximumXValue() - maxX < Vector.MINIMUM_RESOLUTION; }
/** Return true if maxY is as large as the planet model allows. *@return true if maxY has reached its bound. */ public boolean isLargestMaxY(final PlanetModel planetModel) { if (maxY == null) return false; return planetModel.getMaximumYValue() - maxY < Vector.MINIMUM_RESOLUTION; }
/** Return true if maxZ is as large as the planet model allows. *@return true if maxZ has reached its bound. */ public boolean isLargestMaxZ(final PlanetModel planetModel) { if (maxZ == null) return false; return planetModel.getMaximumZValue() - maxZ < Vector.MINIMUM_RESOLUTION; }
final double cutoffOffset = this.sinAngle * planetModel.getMinimumMagnitude();
super(planetModel); assert planetModel.pointOnSurface(testPoint.x, testPoint.y, testPoint.z) : "Test point is not on the ellipsoid surface"; Edge firstEdge = null; for (final GeoPoint thisGeoPoint : shapePoints) { assert planetModel.pointOnSurface(thisGeoPoint) : "Polygon edge point must be on surface; "+thisGeoPoint+" is not"; final Edge edge = new Edge(planetModel, lastGeoPoint, thisGeoPoint); if (edge.isWithin(testPoint.x, testPoint.y, testPoint.z)) { if (-testPoint1FixedYAbovePlane.D - planetModel.getMaximumYValue() > NEAR_EDGE_CUTOFF || planetModel.getMinimumYValue() + testPoint1FixedYAbovePlane.D > NEAR_EDGE_CUTOFF) { testPoint1FixedYAbovePlane = null; if (-testPoint1FixedYBelowPlane.D - planetModel.getMaximumYValue() > NEAR_EDGE_CUTOFF || planetModel.getMinimumYValue() + testPoint1FixedYBelowPlane.D > NEAR_EDGE_CUTOFF) { testPoint1FixedYBelowPlane = null; if (-testPoint1FixedXAbovePlane.D - planetModel.getMaximumXValue() > NEAR_EDGE_CUTOFF || planetModel.getMinimumXValue() + testPoint1FixedXAbovePlane.D > NEAR_EDGE_CUTOFF) { testPoint1FixedXAbovePlane = null; if (-testPoint1FixedXBelowPlane.D - planetModel.getMaximumXValue() > NEAR_EDGE_CUTOFF || planetModel.getMinimumXValue() + testPoint1FixedXBelowPlane.D > NEAR_EDGE_CUTOFF) { testPoint1FixedXBelowPlane = null; if (-testPoint1FixedZAbovePlane.D - planetModel.getMaximumZValue() > NEAR_EDGE_CUTOFF ||planetModel.getMinimumZValue() + testPoint1FixedZAbovePlane.D > NEAR_EDGE_CUTOFF) { testPoint1FixedZAbovePlane = null; if (-testPoint1FixedZBelowPlane.D - planetModel.getMaximumZValue() > NEAR_EDGE_CUTOFF || planetModel.getMinimumZValue() + testPoint1FixedZBelowPlane.D > NEAR_EDGE_CUTOFF) { testPoint1FixedZBelowPlane = null;
@Override public double distance(Point from, Point to) { if (from instanceof Geo3dPointShape && to instanceof Geo3dPointShape) { GeoPointShape pointShape1 = ((Geo3dPointShape) from).shape; GeoPointShape pointShape2 = ((Geo3dPointShape) to).shape; return planetModel.surfaceDistance(pointShape1.getCenter(), pointShape2.getCenter()) * DistanceUtils.RADIANS_TO_DEGREES; } return distance(from, to.getX(), to.getY()); }
@Override public Point pointOnBearing(Point from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse) { Geo3dPointShape geoFrom = (Geo3dPointShape) from; GeoPoint point = (GeoPoint) geoFrom.shape; double dist = DistanceUtils.DEGREES_TO_RADIANS * distDEG; double bearing = DistanceUtils.DEGREES_TO_RADIANS * bearingDEG; GeoPoint newPoint = planetModel.surfacePointOnBearing(point, dist, bearing); double newLat = newPoint.getLatitude() * DistanceUtils.RADIANS_TO_DEGREES; double newLon = newPoint.getLongitude() * DistanceUtils.RADIANS_TO_DEGREES; if (reuse != null) { reuse.reset(newLon, newLat); return reuse; } else { return ctx.getShapeFactory().pointXY(newLon, newLat); } }