/** * Evaluate the plane equation for a given point, as represented * by a vector. * * @param x is the x value. * @param y is the y value. * @param z is the z value. * @return true if the result is on the plane. */ public boolean evaluateIsZero(final double x, final double y, final double z) { return Math.abs(evaluate(x, y, z)) < MINIMUM_RESOLUTION; }
/** * Evaluate the plane equation for a given point, as represented * by a vector. * * @param v is the vector. * @return true if the result is on the plane. */ public boolean evaluateIsZero(final Vector v) { return Math.abs(evaluate(v)) < MINIMUM_RESOLUTION; }
/** * Compute normal distance from plane to a vector. * @param x is the vector x. * @param y is the vector y. * @param z is the vector z. * @param bounds are the bounds which constrain the intersection point. * @return the normal distance. */ public double normalDistance(final double x, final double y, final double z, final Membership... bounds) { final double dist = evaluate(x,y,z); final double perpX = x - dist * this.x; final double perpY = y - dist * this.y; final double perpZ = z - dist * this.z; if (!meetsAllBounds(perpX, perpY, perpZ, bounds)) { return Double.POSITIVE_INFINITY; } return Math.abs(dist); }
/** Given a point on the plane and the ellipsoid, this method looks for a pair of adjoining points on either side of the plane, which are * about MINIMUM_RESOLUTION away from the given point. This only works for planes which go through the center of the world. * Returns null if the planes are effectively parallel and reasonable adjoining points cannot be determined. */ private GeoPoint[] findAdjoiningPoints(final Plane plane, final GeoPoint pointOnPlane, final Plane envelopePlane) { // Compute a normalized perpendicular vector final Vector perpendicular = new Vector(plane, pointOnPlane); double distanceFactor = 0.0; for (int i = 0; i < MAX_ITERATIONS; i++) { distanceFactor += DELTA_DISTANCE; // Compute two new points along this vector from the original final GeoPoint pointA = planetModel.createSurfacePoint(pointOnPlane.x + perpendicular.x * distanceFactor, pointOnPlane.y + perpendicular.y * distanceFactor, pointOnPlane.z + perpendicular.z * distanceFactor); final GeoPoint pointB = planetModel.createSurfacePoint(pointOnPlane.x - perpendicular.x * distanceFactor, pointOnPlane.y - perpendicular.y * distanceFactor, pointOnPlane.z - perpendicular.z * distanceFactor); if (Math.abs(envelopePlane.evaluate(pointA)) > OFF_PLANE_AMOUNT && Math.abs(envelopePlane.evaluate(pointB)) > OFF_PLANE_AMOUNT) { //System.out.println("Distance: "+computeSquaredDistance(rval[0], pointOnPlane)+" and "+computeSquaredDistance(rval[1], pointOnPlane)); return new GeoPoint[]{pointA, pointB}; } // Loop back around and use a bigger delta } // Had to abort, so return null. //System.out.println(" Adjoining points not found. Are planes parallel? edge = "+plane+"; envelope = "+envelopePlane+"; perpendicular = "+perpendicular); return null; }