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 Vectoradd(Triple triple)<T extends Triple>
Tadd(Triple triple, DoubleTriFunction<T> creator)Vectorcross(Vector v)Calculates the cross product of twoVectors.<T extends Vector>
Tcross(Vector v, DoubleTriFunction<T> creator)Calculates the cross product of twoVectors.doubledot(Triple v)Calculates the dot product of twoVectorsdoublelength()Calculates the length of thisVector.Vectorreversed()An alias forscale(double)with factor -1.Vectorscale(double factor)<T extends Vector>
Tscale(double factor, DoubleTriFunction<T> creator)doublesquareLength()Calculates the square of the length of thisVector.Vectorsubtract(Vector vector)<T extends Vector>
Tsubtract(Vector vector, DoubleTriFunction<T> creator)java.lang.StringtoString()Returns theTripleas 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 theVectoris 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 twoVectors.- Type Parameters:
T- The type of Triple to return.- Parameters:
v- TheVectorby which to multiply thisVectorcreator- A function which receives three doubles and returns a newVector- Returns:
- The resulting
Vectorwhich is the cross product of the twoVectors, but of the concrete type as returned bycreator
-
cross
Calculates the cross product of twoVectors.- Parameters:
v- TheVectorby which to multiply thisVector- Returns:
- The resulting
Vectorwhich is the cross product of the twoVectors - Throws:
ZeroVectorException- if the result vector is the zero vector.
-
dot
Calculates the dot product of twoVectors -
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:TripleReturns theTripleas a string in the cartesian representation, e.g. "(0, 0, 0)"
-