/** * sets the vector to new vector * * @param V Vector to be set */ public void set(Vector3D v) { x = v.getX(); y = v.getY(); z = v.getZ(); }
/** * construct a new vector between two points * * @param point1 : initial vector * @param point2 : final vector */ public Vector3D(Vector3D point1, Vector3D point2) { this( point2.getX() - point1.getX(), point2.getY() - point1.getY(), point2.getZ() - point1.getZ()); }
/** * Constructs a new <code>Vector</code> that is the copy of specified object * * @param v : the <code>Vector</code> object to copy */ public Vector3D(Vector3D v) { x = v.getX(); y = v.getY(); z = v.getZ(); edge = v.edge; }
/** * Computes the dot product of the two vectors, defined by : * * <p><code> x1*x2 + y1*y2 + z1*z2</code> * * <p>Dot product is zero if the vectors defined by the 2 vectors are orthogonal. It is positive * if vectors are in the same direction, and negative if they are in opposite direction. */ public static final double dotProduct(Vector3D v1, Vector3D v2) { return v1.getX() * v2.getX() + v1.getY() * v2.getY() + v1.getZ() * v2.getZ(); }
/** * Computes the difference of the two vectors. * * @param v1 : left vector * @param v2 : right Vector * @return new vector obtained by subtracting right vector from left vector */ public Vector3D subtractVectors(Vector3D v1, Vector3D v2) { return new Vector3D(v1.getX() - v2.getX(), v1.getY() - v2.getY(), v1.getZ() - v2.getZ()); }
/** * Computes the sum of the two vectors. * * @param v1 : left vector * @param v1: right Vector * @return new vector representing sum of two vectors */ public Vector3D addVectors(Vector3D v1, Vector3D v2) { return new Vector3D(v1.getX() + v2.getX(), v1.getY() + v2.getY(), v1.getZ() + v2.getZ()); }