import java.lang.*; public class XYZVector extends Object implements Cloneable { public double x, y, z; private double magnitude; public XYZVector(double xx, double yy, double zz) { x = xx; y = yy; z = zz; magnitude = Math.sqrt(x*x + y*y + z*z); } public XYZVector(double x0, double y0, double z0, double x1, double y1, double z1) { x = x1-x0; y = y1-y0; z = z1-z0; magnitude = Math.sqrt(x*x + y*y + z*z); } public synchronized Object clone() { XYZVector b = new XYZVector(x, y, z); return b; } public static double dotProduct(XYZVector a, XYZVector b) { return (a.x * b.x + a.y * b.y + a.z * b.z); } public static XYZVector normalize(XYZVector b) { XYZVector a = (XYZVector) b.clone(); if (a.magnitude != 1.0) { a.x /= a.magnitude; a.y /= a.magnitude; a.z /= a.magnitude; a.magnitude = 1.0; } return a; } public void normalize() { if (magnitude != 1.0) { x /= magnitude; y /= magnitude; z /= magnitude; magnitude = 1.0; } } public static XYZVector plus(XYZVector a, XYZVector b) { return new XYZVector(a.x + b.x, a.y + b.y, a.z + b.z); } public static XYZVector reverse(XYZVector a) { return new XYZVector(-a.x, -a.y, -a.z); } public static XYZVector minus(XYZVector a, XYZVector b) { return plus(a, reverse(b)); } public double getMagnitude() { return magnitude; } }