Package com.badlogic.gdx.math
Interface Vector<T extends Vector<T>>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
add(T v)
Adds the given vector to this vectorT
clamp(float min, float max)
Clamps this vector's length to given min and max valuesT
cpy()
float
dot(T v)
float
dst(T v)
float
dst2(T v)
This method is faster thandst(Vector)
because it avoids calculating a square root.boolean
epsilonEquals(T other, float epsilon)
Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.boolean
hasOppositeDirection(T other)
boolean
hasSameDirection(T other)
T
interpolate(T target, float alpha, Interpolation interpolator)
Interpolates between this vector and the given target vector by alpha (within range [0,1]) using the given Interpolation method.boolean
isCollinear(T other)
boolean
isCollinear(T other, float epsilon)
boolean
isCollinearOpposite(T other)
boolean
isCollinearOpposite(T other, float epsilon)
boolean
isOnLine(T other)
boolean
isOnLine(T other, float epsilon)
boolean
isPerpendicular(T other)
boolean
isPerpendicular(T other, float epsilon)
boolean
isUnit()
boolean
isUnit(float margin)
boolean
isZero()
boolean
isZero(float margin)
float
len()
float
len2()
This method is faster thanlen()
because it avoids calculating a square root.T
lerp(T target, float alpha)
Linearly interpolates between this vector and the target vector by alpha which is in the range [0,1].T
limit(float limit)
Limits the length of this vector, based on the desired maximum length.T
limit2(float limit2)
Limits the length of this vector, based on the desired maximum length squared.T
mulAdd(T v, float scalar)
First scale a supplied vector, then add it to this vector.T
mulAdd(T v, T mulVec)
First scale a supplied vector, then add it to this vector.T
nor()
Normalizes this vector.T
scl(float scalar)
Scales this vector by a scalarT
scl(T v)
Scales this vector by another vectorT
set(T v)
Sets this vector from the given vectorT
setLength(float len)
Sets the length of this vector.T
setLength2(float len2)
Sets the length of this vector, based on the square of the desired length.T
setToRandomDirection()
Sets this vector to the unit vector with a random directionT
setZero()
Sets the components of this vector to 0T
sub(T v)
Subtracts the given vector from this vector.
-
-
-
Method Detail
-
cpy
T cpy()
- Returns:
- a copy of this vector
-
len
float len()
- Returns:
- The Euclidean length
-
len2
float len2()
This method is faster thanlen()
because it avoids calculating a square root. It is useful for comparisons, but not for getting exact lengths, as the return value is the square of the actual length.- Returns:
- The squared Euclidean length
-
limit
T limit(float limit)
Limits the length of this vector, based on the desired maximum length.- Parameters:
limit
- desired maximum length for this vector- Returns:
- this vector for chaining
-
limit2
T limit2(float limit2)
Limits the length of this vector, based on the desired maximum length squared. This method is slightly faster than limit().- Parameters:
limit2
- squared desired maximum length for this vector- Returns:
- this vector for chaining
- See Also:
len2()
-
setLength
T setLength(float len)
Sets the length of this vector. Does nothing if this vector is zero.- Parameters:
len
- desired length for this vector- Returns:
- this vector for chaining
-
setLength2
T setLength2(float len2)
Sets the length of this vector, based on the square of the desired length. Does nothing if this vector is zero. This method is slightly faster than setLength().- Parameters:
len2
- desired square of the length for this vector- Returns:
- this vector for chaining
- See Also:
len2()
-
clamp
T clamp(float min, float max)
Clamps this vector's length to given min and max values- Parameters:
min
- Min lengthmax
- Max length- Returns:
- This vector for chaining
-
set
T set(T v)
Sets this vector from the given vector- Parameters:
v
- The vector- Returns:
- This vector for chaining
-
sub
T sub(T v)
Subtracts the given vector from this vector.- Parameters:
v
- The vector- Returns:
- This vector for chaining
-
nor
T nor()
Normalizes this vector. Does nothing if it is zero.- Returns:
- This vector for chaining
-
add
T add(T v)
Adds the given vector to this vector- Parameters:
v
- The vector- Returns:
- This vector for chaining
-
dot
float dot(T v)
- Parameters:
v
- The other vector- Returns:
- The dot product between this and the other vector
-
scl
T scl(float scalar)
Scales this vector by a scalar- Parameters:
scalar
- The scalar- Returns:
- This vector for chaining
-
dst
float dst(T v)
- Parameters:
v
- The other vector- Returns:
- the distance between this and the other vector
-
dst2
float dst2(T v)
This method is faster thandst(Vector)
because it avoids calculating a square root. It is useful for comparisons, but not for getting accurate distances, as the return value is the square of the actual distance.- Parameters:
v
- The other vector- Returns:
- the squared distance between this and the other vector
-
lerp
T lerp(T target, float alpha)
Linearly interpolates between this vector and the target vector by alpha which is in the range [0,1]. The result is stored in this vector.- Parameters:
target
- The target vectoralpha
- The interpolation coefficient- Returns:
- This vector for chaining.
-
interpolate
T interpolate(T target, float alpha, Interpolation interpolator)
Interpolates between this vector and the given target vector by alpha (within range [0,1]) using the given Interpolation method. the result is stored in this vector.- Parameters:
target
- The target vectoralpha
- The interpolation coefficientinterpolator
- An Interpolation object describing the used interpolation method- Returns:
- This vector for chaining.
-
setToRandomDirection
T setToRandomDirection()
Sets this vector to the unit vector with a random direction- Returns:
- This vector for chaining
-
isUnit
boolean isUnit()
- Returns:
- Whether this vector is a unit length vector
-
isUnit
boolean isUnit(float margin)
- Returns:
- Whether this vector is a unit length vector within the given margin.
-
isZero
boolean isZero()
- Returns:
- Whether this vector is a zero vector
-
isZero
boolean isZero(float margin)
- Returns:
- Whether the length of this vector is smaller than the given margin
-
isOnLine
boolean isOnLine(T other, float epsilon)
- Returns:
- true if this vector is in line with the other vector (either in the same or the opposite direction)
-
isOnLine
boolean isOnLine(T other)
- Returns:
- true if this vector is in line with the other vector (either in the same or the opposite direction)
-
isCollinear
boolean isCollinear(T other, float epsilon)
- Returns:
- true if this vector is collinear with the other vector (
isOnLine(Vector, float)
&&hasSameDirection(Vector)
).
-
isCollinear
boolean isCollinear(T other)
- Returns:
- true if this vector is collinear with the other vector (
isOnLine(Vector)
&&hasSameDirection(Vector)
).
-
isCollinearOpposite
boolean isCollinearOpposite(T other, float epsilon)
- Returns:
- true if this vector is opposite collinear with the other vector (
isOnLine(Vector, float)
&&hasOppositeDirection(Vector)
).
-
isCollinearOpposite
boolean isCollinearOpposite(T other)
- Returns:
- true if this vector is opposite collinear with the other vector (
isOnLine(Vector)
&&hasOppositeDirection(Vector)
).
-
isPerpendicular
boolean isPerpendicular(T other)
- Returns:
- Whether this vector is perpendicular with the other vector. True if the dot product is 0.
-
isPerpendicular
boolean isPerpendicular(T other, float epsilon)
- Parameters:
epsilon
- a positive small number close to zero- Returns:
- Whether this vector is perpendicular with the other vector. True if the dot product is 0.
-
hasSameDirection
boolean hasSameDirection(T other)
- Returns:
- Whether this vector has similar direction compared to the other vector. True if the normalized dot product is > 0.
-
hasOppositeDirection
boolean hasOppositeDirection(T other)
- Returns:
- Whether this vector has opposite direction compared to the other vector. True if the normalized dot product is < 0.
-
epsilonEquals
boolean epsilonEquals(T other, float epsilon)
Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.- Parameters:
other
-epsilon
-- Returns:
- whether the vectors have fuzzy equality.
-
mulAdd
T mulAdd(T v, float scalar)
First scale a supplied vector, then add it to this vector.- Parameters:
v
- addition vectorscalar
- for scaling the addition vector
-
mulAdd
T mulAdd(T v, T mulVec)
First scale a supplied vector, then add it to this vector.- Parameters:
v
- addition vectormulVec
- vector by whose values the addition vector will be scaled
-
setZero
T setZero()
Sets the components of this vector to 0- Returns:
- This vector for chaining
-
-