Package hoverball.math
Class Vector
java.lang.Object
hoverball.math.Vector
public final class Vector
extends java.lang.Object
The class Vector represents a three dimensional vector.
Let be:
a, b, v - vectors
x, y, z - real numbers (as coordinates)
r - real number
c - complex number
A - matrix
v - the vector of the Vector object itself
Operator Overloading for Groovy, Scala, Kotlin and Jython is supported.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description doubleabs()Returns the absolute value [ = | v | ].doubleabs2()Returns the squared absolute value [ = | v |^2 ].Vectoradd(Vector b)Adds a vector [ v = v + b ].static Vectoradd(Vector a, Vector b)Sums two vectors [ = a + b ].Vectordiv(double r)Divides by a real number [ v = v / r ].static doubledot(Vector a, Vector b)Returns the dot product between two vectors [ = < a, b > ].booleanequals(double x, double y, double z)Compares with another vector [ v = (x,y,z) ?booleanequals(java.lang.Object v)Compares with another vector [ v = v ?inthashCode()Returns the hash code [ =####].Vectormul(double r)Multiplies by a real number [ v = v r ].Vectormul(Matrix A)Multiplies by a matrix [ v = v A ].static Vectormul(Vector v, double r)Multiplies a vector by a real number [ = v r ].static Vectormul(Vector v, Matrix A)Multiplies a vector by a matrix [ = v A ].Vectorneg()Negates the vector [ v = -v ].static Vectorneg(Vector v)Creates the negated vector [ = -v ].Vectornorm()Normalizes the absolute value to 1 [ v = v / | v | ].static Vectornorm(Vector v)Creates the normalization of the absolute value to 1 [ = v / | v | ].Vectorsub(Vector b)Substracts a vector [ v = v - b ].static Vectorsub(Vector a, Vector b)Substracts two vectors [ = a - b ].java.lang.StringtoString()String representation [ = "..." ].static Vectorvec(Vector a, Vector b)Returns the three dimensional vector product between two vectors [ = a x b ].booleanzero()Tests if zero [ v = 0 ?
-
Field Details
-
Constructor Details
-
Vector
public Vector()Creates a vector with the coordinates (0,0,0). -
Vector
public Vector(double x, double y, double z)Creates a vector with the coordinates (x,y,z).- Parameters:
x- x-coordinatey- y-coordinatez- z-coordinate
-
Vector
Creates a vector equal to another.- Parameters:
v- copied vector
-
Vector
Creates a vector from a complex number.The z-coordinate of the vector is set to zero.
- Parameters:
c- complex number
-
-
Method Details
-
hashCode
public int hashCode()Returns the hash code [ =####].- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code
-
toString
public java.lang.String toString()String representation [ = "..." ].- Overrides:
toStringin classjava.lang.Object- Returns:
- the string
-
equals
public boolean equals(java.lang.Object v)Compares with another vector [ v = v ? ].- Overrides:
equalsin classjava.lang.Object- Parameters:
v- vector- Returns:
- the equality
-
equals
public boolean equals(double x, double y, double z)Compares with another vector [ v = (x,y,z) ? ].- Parameters:
x- real numbery- real numberz- real number- Returns:
- the equality
-
add
Adds a vector [ v = v + b ].- Parameters:
b- vector- Returns:
- this
-
sub
Substracts a vector [ v = v - b ].- Parameters:
b- vector- Returns:
- this
-
mul
Multiplies by a real number [ v = v r ].- Parameters:
r- real number- Returns:
- this
-
mul
Multiplies by a matrix [ v = v A ].- Parameters:
A- matrix- Returns:
- this
-
div
Divides by a real number [ v = v / r ].- Parameters:
r- real number- Returns:
- this
-
neg
Negates the vector [ v = -v ].- Returns:
- this
-
zero
public final boolean zero()Tests if zero [ v = 0 ? ].- Returns:
- true, if this vector equals (0,0,0)
-
abs
public final double abs()Returns the absolute value [ = | v | ].- Returns:
- the absolute value
-
abs2
public final double abs2()Returns the squared absolute value [ = | v |^2 ].- Returns:
- the squared absolute value
-
norm
Normalizes the absolute value to 1 [ v = v / | v | ].- Returns:
- this
-
add
Sums two vectors [ = a + b ].- Parameters:
a- vectorb- vector- Returns:
- the sum
-
sub
Substracts two vectors [ = a - b ].- Parameters:
a- vectorb- vector- Returns:
- the difference
-
neg
Creates the negated vector [ = -v ].- Parameters:
v- vector- Returns:
- negated vector
-
norm
Creates the normalization of the absolute value to 1 [ = v / | v | ].- Parameters:
v- vector- Returns:
- die Normierung
-
mul
Multiplies a vector by a real number [ = v r ].- Parameters:
v- vectorr- real number- Returns:
- the product
-
mul
Multiplies a vector by a matrix [ = v A ].- Parameters:
v- vectorA- matrix- Returns:
- the product
-
dot
Returns the dot product between two vectors [ = < a, b > ].- Parameters:
a- vectorb- vector- Returns:
- the dot product
-
vec
Returns the three dimensional vector product between two vectors [ = a x b ].- Parameters:
a- vectorb- vector- Returns:
- the vector product
-