/** * Compute the square of the normal distance to a vector described by a * vector taken from the origin. * Monotonically increasing for arc distances up to PI/2. * * @param v is the vector to compute a distance to. * @return the square of the normal distance. */ public double normalDistanceSquared(final Vector v) { double t = dotProduct(v); double deltaX = this.x * t - v.x; double deltaY = this.y * t - v.y; double deltaZ = this.z * t - v.z; return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ; }
/** * Compute the square of the normal distance to a vector described by a * vector taken from the origin. * Monotonically increasing for arc distances up to PI/2. * * @param x is the x part of the vector to compute a distance to. * @param y is the y part of the vector to compute a distance to. * @param z is the z part of the vector to compute a distance to. * @return the square of the normal distance. */ public double normalDistanceSquared(final double x, final double y, final double z) { double t = dotProduct(x, y, z); double deltaX = this.x * t - x; double deltaY = this.y * t - y; double deltaZ = this.z * t - z; return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ; }
/** Construct a sided plane from two points and a third normal vector. */ public static SidedPlane constructNormalizedPerpendicularSidedPlane(final Vector insidePoint, final Vector normalVector, final Vector point1, final Vector point2) { final Vector pointsVector = new Vector(point1.x - point2.x, point1.y - point2.y, point1.z - point2.z); final Vector newNormalVector = new Vector(normalVector, pointsVector); try { // To construct the plane, we now just need D, which is simply the negative of the evaluation of the circle normal vector at one of the points. return new SidedPlane(insidePoint, newNormalVector, -newNormalVector.dotProduct(point1)); } catch (IllegalArgumentException e) { return null; } }
point1.x - point2.x, point1.y - point2.y, point1.z - point2.z, point2.x - point3.x, point2.y - point3.y, point2.z - point3.z); rval = new SidedPlane(insidePoint, planeNormal, -planeNormal.dotProduct(point2)); } catch (IllegalArgumentException e) { point1.x - point3.x, point1.y - point3.y, point1.z - point3.z, point3.x - point2.x, point3.y - point2.y, point3.z - point2.z); rval = new SidedPlane(insidePoint, planeNormal, -planeNormal.dotProduct(point3)); } catch (IllegalArgumentException e) { point3.x - point1.x, point3.y - point1.y, point3.z - point1.z, point1.x - point2.x, point1.y - point2.y, point1.z - point2.z); rval = new SidedPlane(insidePoint, planeNormal, -planeNormal.dotProduct(point1)); } catch (IllegalArgumentException e) {