package vector; import java.util.Arrays; public class Vector3d { private double[] coord; public Vector3d() { this(0, 0, 0); } public Vector3d(double x, double y, double z) { this.coord = new double[3]; this.coord[0] = x; this.coord[1] = y; this.coord[2] = z; } public double getX() { return this.coord[0]; } public double getY() { return this.coord[1]; } public double getZ() { return this.coord[2]; } public void setX(double x) { this.coord[0] = x; } public void setY(double y) { this.coord[1] = y; } public void setZ(double z) { this.coord[2] = z; } public Vector3d cross(Vector3d other) { Vector3d c = new Vector3d(); c.setX(this.getY() * other.getZ() - this.getZ() * other.getY()); c.setY(this.getZ() * other.getX() - this.getX() * other.getZ()); c.setZ(this.getX() * other.getY() - this.getY() * other.getX()); return c; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(coord); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Vector3d other = (Vector3d) obj; if (!Arrays.equals(coord, other.coord)) { return false; } return true; } @Override public String toString() { return "[ " + this.getX() + " " + this.getY() + " " + this.getZ() + " ]"; } public static Vector3d x() { return new Vector3d(1, 0, 0); } public static Vector3d y() { return new Vector3d(0, 1, 0); } public static Vector3d z() { return new Vector3d(0, 0, 1); } }