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 double
abs()
Returns the absolute value [ = | v | ].double
abs2()
Returns the squared absolute value [ = | v |^2 ].Vector
add(Vector b)
Adds a vector [ v = v + b ].static Vector
add(Vector a, Vector b)
Sums two vectors [ = a + b ].Vector
div(double r)
Divides by a real number [ v = v / r ].static double
dot(Vector a, Vector b)
Returns the dot product between two vectors [ = < a, b > ].boolean
equals(double x, double y, double z)
Compares with another vector [ v = (x,y,z) ?boolean
equals(java.lang.Object v)
Compares with another vector [ v = v ?int
hashCode()
Returns the hash code [ =####
].Vector
mul(double r)
Multiplies by a real number [ v = v r ].Vector
mul(Matrix A)
Multiplies by a matrix [ v = v A ].static Vector
mul(Vector v, double r)
Multiplies a vector by a real number [ = v r ].static Vector
mul(Vector v, Matrix A)
Multiplies a vector by a matrix [ = v A ].Vector
neg()
Negates the vector [ v = -v ].static Vector
neg(Vector v)
Creates the negated vector [ = -v ].Vector
norm()
Normalizes the absolute value to 1 [ v = v / | v | ].static Vector
norm(Vector v)
Creates the normalization of the absolute value to 1 [ = v / | v | ].Vector
sub(Vector b)
Substracts a vector [ v = v - b ].static Vector
sub(Vector a, Vector b)
Substracts two vectors [ = a - b ].java.lang.String
toString()
String representation [ = "..." ].static Vector
vec(Vector a, Vector b)
Returns the three dimensional vector product between two vectors [ = a x b ].boolean
zero()
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:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
-
toString
public java.lang.String toString()String representation [ = "..." ].- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string
-
equals
public boolean equals(java.lang.Object v)Compares with another vector [ v = v ? ].- Overrides:
equals
in 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
-