Package primitives
Class Vector
java.lang.Object
primitives.Triple
primitives.Vector
- Direct Known Subclasses:
NonZeroVector
public class Vector extends Triple
The
Vector
class represents a NonZeroVector
with the single difference that the VectorBase can be the
zero vector. Let me repeat that. This class can have values of (0,0,0).-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Vector
add(Triple triple)
<T extends Triple>
Tadd(Triple triple, DoubleTriFunction<T> creator)
Vector
cross(Vector v)
Calculates the cross product of twoVector
s.<T extends Vector>
Tcross(Vector v, DoubleTriFunction<T> creator)
Calculates the cross product of twoVector
s.double
dot(Triple v)
Calculates the dot product of twoVector
sdouble
length()
Calculates the length of thisVector
.Vector
reversed()
An alias forscale(double)
with factor -1.Vector
scale(double factor)
<T extends Vector>
Tscale(double factor, DoubleTriFunction<T> creator)
double
squareLength()
Calculates the square of the length of thisVector
.Vector
subtract(Vector vector)
<T extends Vector>
Tsubtract(Vector vector, DoubleTriFunction<T> creator)
java.lang.String
toString()
Returns theTriple
as a string in the cartesian representation, e.g.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Vector
public Vector(double x, double y, double z)This constructor accepts 3 doubles and returns the appropriateVector
- 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 theVector
is the zero vector.
-
-
Method Details
-
add
-
add
-
subtract
-
subtract
-
scale
-
scale
- Parameters:
factor
- The scalar by which to multiply thisVector
- Returns:
- New scaled
Vector
- Throws:
ZeroVectorException
- if the scale factor is zero.
-
reversed
An alias forscale(double)
with factor -1.- Returns:
- New reversed
Vector
-
cross
Calculates the cross product of twoVector
s.- Type Parameters:
T
- The type of Triple to return.- Parameters:
v
- TheVector
by which to multiply thisVector
creator
- A function which receives three doubles and returns a newVector
- Returns:
- The resulting
Vector
which is the cross product of the twoVector
s, but of the concrete type as returned bycreator
-
cross
Calculates the cross product of twoVector
s.- Parameters:
v
- TheVector
by which to multiply thisVector
- Returns:
- The resulting
Vector
which is the cross product of the twoVector
s - Throws:
ZeroVectorException
- if the result vector is the zero vector.
-
dot
Calculates the dot product of twoVector
s -
length
public double length()Calculates the length of thisVector
.- Returns:
- The length of this
Vector
.
-
squareLength
public double squareLength()Calculates the square of the length of thisVector
.- Returns:
- The square of the length of this
Vector
.
-
toString
public java.lang.String toString()Description copied from class:Triple
Returns theTriple
as a string in the cartesian representation, e.g. "(0, 0, 0)"
-