Package primitives
Class NonZeroVector
java.lang.Object
primitives.Triple
primitives.Vector
primitives.NonZeroVector
- Direct Known Subclasses:
NormalizedVector
public class NonZeroVector extends Vector
The
NonZeroVector class represents a NonZeroVector with it's base at the
origin and it's head at the Point 'head'.-
Field Summary
-
Constructor Summary
Constructors Constructor Description NonZeroVector(double x, double y, double z)This constructor accepts 3 doubles and returns the appropriateNonZeroVector -
Method Summary
Modifier and Type Method Description NonZeroVectoradd(Triple triple)Adds twoNonZeroVectors and returns a newNonZeroVector.doubleangle(NonZeroVector v)Calculates the angle in radians between this vector and the given vector.NonZeroVectorcross(NonZeroVector vector)Calculates the cross product of twoNonZeroVectors.NormalizedVectornormalized()Creates a newNonZeroVectorwith the same direction as this one but with a magnitude of one.NonZeroVectorreversed()An alias forVector.scale(double)with factor -1.NonZeroVectorscale(double factor)Constructs a newNonZeroVectorwhich is a scalar multiplication of thisNonZeroVectorby a scalar.NonZeroVectorsubtract(Vector vector)Subtracts twoNonZeroVectors and returns a newNonZeroVector.Methods inherited from class primitives.Vector
add, cross, cross, dot, length, scale, squareLength, subtract, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
NonZeroVector
public NonZeroVector(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 theNonZeroVectoris the zero vector.
-
-
Method Details
-
add
Adds twoNonZeroVectors and returns a newNonZeroVector.- Overrides:
addin classVector- Parameters:
triple- TheTriplewhich is to be added to thisNonZeroVector.- Returns:
- The sum of the two
NonZeroVectors. - Throws:
ZeroVectorException- when adding aNonZeroVectorwith its reverse.
-
subtract
Subtracts twoNonZeroVectors and returns a newNonZeroVector.- Overrides:
subtractin classVector- Parameters:
vector- TheVectorto be subtracted from thisNonZeroVector.- Returns:
- The sum of this
NonZeroVectorand the negation of the givenVector. - Throws:
ZeroVectorException- if aNonZeroVectoris subtracted from itself.
-
scale
Constructs a newNonZeroVectorwhich is a scalar multiplication of thisNonZeroVectorby a scalar.- Overrides:
scalein classVector- Parameters:
factor- The scalar by which to multiply thisNonZeroVector- Returns:
- New scaled
NonZeroVector - Throws:
ZeroVectorException- if the scale factor is zero.
-
cross
Calculates the cross product of twoNonZeroVectors.- Parameters:
vector- TheNonZeroVectorby which to multiply thisNonZeroVector- Returns:
- The resulting
NonZeroVectorwhich is the cross product of the twoNonZeroVectors - Throws:
ZeroVectorException- if the result vector is the zero vector.
-
normalized
Creates a newNonZeroVectorwith the same direction as this one but with a magnitude of one.- Returns:
- new
NonZeroVector
-
angle
Calculates the angle in radians between this vector and the given vector. The angle is normalized between zero and Pi.- Parameters:
v- The other vector to be used to calculate the angle.- Returns:
- The angle in radians between the vectors between zero and Pi.
-
reversed
Description copied from class:VectorAn alias forVector.scale(double)with factor -1.
-