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 NonZeroVector
add(Triple triple)
Adds twoNonZeroVector
s and returns a newNonZeroVector
.double
angle(NonZeroVector v)
Calculates the angle in radians between this vector and the given vector.NonZeroVector
cross(NonZeroVector vector)
Calculates the cross product of twoNonZeroVector
s.NormalizedVector
normalized()
Creates a newNonZeroVector
with the same direction as this one but with a magnitude of one.NonZeroVector
reversed()
An alias forVector.scale(double)
with factor -1.NonZeroVector
scale(double factor)
Constructs a newNonZeroVector
which is a scalar multiplication of thisNonZeroVector
by a scalar.NonZeroVector
subtract(Vector vector)
Subtracts twoNonZeroVector
s and returns a newNonZeroVector
.Methods inherited from class primitives.Vector
add, cross, cross, dot, length, scale, squareLength, subtract, toString
Methods 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 theNonZeroVector
is the zero vector.
-
-
Method Details
-
add
Adds twoNonZeroVector
s and returns a newNonZeroVector
.- Overrides:
add
in classVector
- Parameters:
triple
- TheTriple
which is to be added to thisNonZeroVector
.- Returns:
- The sum of the two
NonZeroVector
s. - Throws:
ZeroVectorException
- when adding aNonZeroVector
with its reverse.
-
subtract
Subtracts twoNonZeroVector
s and returns a newNonZeroVector
.- Overrides:
subtract
in classVector
- Parameters:
vector
- TheVector
to be subtracted from thisNonZeroVector
.- Returns:
- The sum of this
NonZeroVector
and the negation of the givenVector
. - Throws:
ZeroVectorException
- if aNonZeroVector
is subtracted from itself.
-
scale
Constructs a newNonZeroVector
which is a scalar multiplication of thisNonZeroVector
by a scalar.- Overrides:
scale
in 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 twoNonZeroVector
s.- Parameters:
vector
- TheNonZeroVector
by which to multiply thisNonZeroVector
- Returns:
- The resulting
NonZeroVector
which is the cross product of the twoNonZeroVector
s - Throws:
ZeroVectorException
- if the result vector is the zero vector.
-
normalized
Creates a newNonZeroVector
with 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:Vector
An alias forVector.scale(double)
with factor -1.
-