/** * Translate vector. */ public Vector translate(final double xOffset, final double yOffset, final double zOffset) { return new Vector(x - xOffset, y - yOffset, z - zOffset); }
/** * Rotate vector counter-clockwise in x-y by an angle, expressed as sin and cos. */ public Vector rotateXY(final double sinAngle, final double cosAngle) { return new Vector(x * cosAngle - y * sinAngle, x * sinAngle + y * cosAngle, z); }
/** * Rotate vector counter-clockwise in x-z by an angle, expressed as sin and cos. */ public Vector rotateXZ(final double sinAngle, final double cosAngle) { return new Vector(x * cosAngle - z * sinAngle, y, x * sinAngle + z * cosAngle); }
/** * Rotate vector counter-clockwise in z-y by an angle, expressed as sin and cos. */ public Vector rotateZY(final double sinAngle, final double cosAngle) { return new Vector(x, z * sinAngle + y * cosAngle, z * cosAngle - y * sinAngle); }
/** 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; } }
/** * Compute a normalized unit vector based on the current vector. * * @return the normalized vector, or null if the current vector has * a magnitude of zero. */ public Vector normalize() { double denom = magnitude(); if (denom < MINIMUM_RESOLUTION) // Degenerate, can't normalize return null; double normFactor = 1.0 / denom; return new Vector(x * normFactor, y * normFactor, z * normFactor); }
final Vector planeNormal = new Vector( point1.x - point2.x, point1.y - point2.y, point1.z - point2.z, point2.x - point3.x, point2.y - point3.y, point2.z - point3.z); final Vector planeNormal = new Vector( point1.x - point3.x, point1.y - point3.y, point1.z - point3.z, point3.x - point2.x, point3.y - point2.y, point3.z - point2.z); final Vector planeNormal = new Vector( point3.x - point1.x, point3.y - point1.y, point3.z - point1.z, point1.x - point2.x, point1.y - point2.y, point1.z - point2.z);
/** 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; }
final double sinNewAngle = Math.sin(newAngle); final double cosNewAngle = Math.cos(newAngle); final Vector newVector = new Vector(cosNewAngle * startMagnitude, sinNewAngle * startMagnitude, 0.0); returnValues[i] = reverseModify(planetModel, newVector, transX, transY, transZ, sinRA, cosRA, sinHA, cosHA);