Class Vector3D

Hierarchy: Object , Vector3D
public class Vector3D
Represents a vector in 3-dimensional Cartesian space.
Authors:
mdavis
public Vector3D(Coordinate v)
Creates a new 3D vector from a Coordinate. The coordinate should have the X,Y and Z ordinates specified.
Parameters:
coord - coord the Coordinate to copy
Returns:
a new vector
public Vector3D(Coordinate from, Coordinate to)
Creates a vector with the direction and magnitude of the difference between the to and from Coordinates.
Parameters:
from - from the origin Coordinate
to - to the destination Coordinate
Returns:
a new vector
public Vector3D(double x, double y, double z)
Creates a vector with the givne components.
Parameters:
x - x the X component
y - y the Y component
z - z the Z component
public static double dot(Coordinate A, Coordinate B, Coordinate C, Coordinate D)
Computes the dot product of the 3D vectors AB and CD.
Parameters:
A - A the start point of the first vector
B - B the end point of the first vector
C - C the start point of the second vector
D - D the end point of the second vector
Returns:
the dot product
public static Vector3D create(double x, double y, double z)
Creates a new vector with given X, Y and Z components.
Parameters:
x - x the X component
y - y the Y component
z - z the Z component
Returns:
a new vector
public static Vector3D create(Coordinate coord)
Creates a vector from a 3D Coordinate. The coordinate should have the X,Y and Z ordinates specified.
Parameters:
coord - coord the Coordinate to copy
Returns:
a new vector
public static double dot(Coordinate v1, Coordinate v2)
Computes the 3D dot-product of two Coordinates.
Parameters:
v1 - v1 the first vector
v2 - v2 the second vector
Returns:
the dot product of the vectors
public double getX()
Gets the X component of this vector.
Returns:
the value of the X component
public double getY()
Gets the Y component of this vector.
Returns:
the value of the Y component
public double getZ()
Gets the Z component of this vector.
Returns:
the value of the Z component
public Vector3D add(Vector3D v)
Computes a vector which is the sum of this vector and the given vector.
Parameters:
v - v the vector to add
Returns:
the sum of this and v
public Vector3D subtract(Vector3D v)
Computes a vector which is the difference of this vector and the given vector.
Parameters:
v - v the vector to subtract
Returns:
the difference of this and v
public Vector3D divide(double d)
Creates a new vector which has the same direction and with length equals to the length of this vector divided by the scalar value d.
Parameters:
d - d the scalar divisor
Returns:
a new vector with divided length
public double dot(Vector3D v)
Computes the dot-product of two vectors
Parameters:
v - v a vector
Returns:
the dot product of the vectors
public double length()
Computes the length of this vector.
Returns:
the length of the vector
public static double length(Coordinate v)
Computes the length of a vector.
Parameters:
v - v a coordinate representing a 3D vector
Returns:
the length of the vector
public Vector3D normalize()
Computes a vector having identical direction but normalized to have length 1.
Returns:
a new normalized vector
public static Coordinate normalize(Coordinate v)
Computes a vector having identical direction but normalized to have length 1.
Parameters:
v - v a coordinate representing a 3D vector
Returns:
a coordinate representing the normalized vector
public String toString()
Gets a string representation of this vector
Returns:
a string representing this vector
public boolean equals(Object o)
Tests if a vector o has the same values for the components.
Parameters:
o - o a Vector3D with which to do the comparison.
Returns:
true if other is a Vector3D with the same values for the x and y components.
public int hashCode()
Gets a hashcode for this vector.
Returns:
a hashcode for this vector