Package primitives
Class NormalizedVector
java.lang.Object
primitives.Triple
primitives.Vector
primitives.NonZeroVector
primitives.NormalizedVector
public class NormalizedVector extends NonZeroVector
This class represents a special kind of
NonZeroVector whose length is one.-
Field Summary
Fields Modifier and Type Field Description static NormalizedVectorIThe I unit vectorstatic NormalizedVectorJThe J unit vectorstatic NormalizedVectorKThe K unit vector -
Constructor Summary
Constructors Constructor Description NormalizedVector(double x, double y, double z)This constructor accepts 3 doubles and returns the appropriateNonZeroVector.NormalizedVector(NonZeroVector vector)Constructs aNormalizedVectorfrom a not necessarily normalizedNonZeroVector -
Method Summary
Modifier and Type Method Description doublelength()Gets the length of the vector.NormalizedVectornormalized()Creates a newNonZeroVectorwith the same direction as this one but with a magnitude of one.NormalizedVectorreversed()Calculates a newNormalizedVectorwith the opposite direction to this vector.doublesquareLength()Gets the length of the vector squared.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Field Details
-
I
The I unit vector -
J
The J unit vector -
K
The K unit vector
-
-
Constructor Details
-
NormalizedVector
Constructs aNormalizedVectorfrom a not necessarily normalizedNonZeroVector- Parameters:
vector- The unnormalized vector.
-
NormalizedVector
public NormalizedVector(double x, double y, double z)This constructor accepts 3 doubles and returns the appropriateNonZeroVector.- Parameters:
x- The value of the x coordinate.y- The value of the y coordinate.z- The value of the z coordinate.- Throws:
ZeroVectorException- if the x, y, and z are all zero.
-
-
Method Details
-
normalized
Description copied from class:NonZeroVectorCreates a newNonZeroVectorwith the same direction as this one but with a magnitude of one.- Overrides:
normalizedin classNonZeroVector- Returns:
- new
NonZeroVector
-
reversed
Calculates a newNormalizedVectorwith the opposite direction to this vector.- Overrides:
reversedin classNonZeroVector- Returns:
- Since the magnitude is unchanged, the returned
NonZeroVectoris aNormalizedVector.
-
length
public double length()Gets the length of the vector. -
squareLength
public double squareLength()Gets the length of the vector squared.- Overrides:
squareLengthin classVector- Returns:
- 1.0 since a normalized vector by definition has a length of one.
-