Package edu.cnu.mdi.geometry
Class Vector
java.lang.Object
edu.cnu.mdi.geometry.Point
edu.cnu.mdi.geometry.Vector
A mutable three-dimensional Cartesian vector.
This class extends Point so that existing MDI code can use the same
public x, y, and z fields for points and vectors. The
distinction is semantic: a Point represents a location, while a
Vector represents a displacement or direction.
- Author:
- heddle
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic VectorComputes the cross producta x b.static voidComputes the cross producta x band stores it in an existing vector.doublelength()Computes this vector's Euclidean length.doubleComputes the square of this vector's Euclidean length.Computes a unit vector in the same direction as this vector.
-
Constructor Details
-
Vector
public Vector()Creates the zero vector. -
Vector
Creates a vector from a point-like tuple.- Parameters:
p- the tuple whose components will be copied- Throws:
NullPointerException- ifpisnull
-
Vector
public Vector(double x, double y, double z) Creates a vector from its Cartesian components.- Parameters:
x- the x componenty- the y componentz- the z component
-
-
Method Details
-
lengthSquared
public double lengthSquared()Computes the square of this vector's Euclidean length.- Returns:
x*x + y*y + z*z
-
length
public double length()Computes this vector's Euclidean length.- Returns:
- the vector length
-
cross
Computes the cross producta x b.- Parameters:
a- the first vectorb- the second vector- Returns:
- a new vector containing
a x b - Throws:
NullPointerException- if either argument isnull
-
cross
Computes the cross producta x band stores it in an existing vector.All three result components are computed into temporaries before any are written, so the output vector may safely be the same object as either input.
- Parameters:
a- the first vectorb- the second vectorc- upon return, containsa x b- Throws:
NullPointerException- if any argument isnull
-
unitVector
Computes a unit vector in the same direction as this vector.- Returns:
- a new unit vector, or
nullif this vector is too close to zero to normalize
-