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 NormalizedVector
I
The I unit vectorstatic NormalizedVector
J
The J unit vectorstatic NormalizedVector
K
The 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 aNormalizedVector
from a not necessarily normalizedNonZeroVector
-
Method Summary
Modifier and Type Method Description double
length()
Gets the length of the vector.NormalizedVector
normalized()
Creates a newNonZeroVector
with the same direction as this one but with a magnitude of one.NormalizedVector
reversed()
Calculates a newNormalizedVector
with the opposite direction to this vector.double
squareLength()
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 aNormalizedVector
from 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:NonZeroVector
Creates a newNonZeroVector
with the same direction as this one but with a magnitude of one.- Overrides:
normalized
in classNonZeroVector
- Returns:
- new
NonZeroVector
-
reversed
Calculates a newNormalizedVector
with the opposite direction to this vector.- Overrides:
reversed
in classNonZeroVector
- Returns:
- Since the magnitude is unchanged, the returned
NonZeroVector
is aNormalizedVector
.
-
length
public double length()Gets the length of the vector. -
squareLength
public double squareLength()Gets the length of the vector squared.- Overrides:
squareLength
in classVector
- Returns:
- 1.0 since a normalized vector by definition has a length of one.
-