APIdia Launch Partner
Top Description Methods
com.badlogic.gdx.math

public Interface Vector<T extends Vector<T>>

Known Direct Implementers
com.badlogic.gdx.math.Vector2, com.badlogic.gdx.math.Vector3, com.badlogic.gdx.math.Vector4

Encapsulates a general vector. Allows chaining operations by returning a reference to itself in all modification methods. See Vector2 and Vector3 for specific implementations.
Author
Xoppa

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

This vector for chaining
add
(T
The vector
v
)

Adds the given vector to this vector

public T

Returns:

This vector for chaining
clamp
(float
Min length
min
,
float
Max length
max
)

Clamps this vector's length to given min and max values

public T
cpy()

Returns: a copy of this vector

public float
dot(T
The other vector
v
)

Returns: The dot product between this and the other vector

public float
dst(T
The other vector
v
)

Returns: the distance between this and the other vector

public float

Returns:

the squared distance between this and the other vector
dst2
(T
The other vector
v
)

This method is faster than Vector#dst(Vector) because it avoids calculating a square root.

public boolean

Returns:

whether the vectors have fuzzy equality.
epsilonEquals
(T other, float epsilon)

Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.

public boolean
hasOppositeDirection(T other)

Returns: Whether this vector has opposite direction compared to the other vector.

public boolean
hasSameDirection(T other)

Returns: Whether this vector has similar direction compared to the other vector.

public T

Returns:

This vector for chaining.
interpolate
(T
The target vector
target
,
float
The interpolation coefficient
alpha
,
Interpolation
An Interpolation object describing the used interpolation method
interpolator
)

Interpolates between this vector and the given target vector by alpha (within range [0,1]) using the given Interpolation method.

public boolean
isCollinear(T other, float epsilon)

Returns: true if this vector is collinear with the other vector (isOnLine(Vector, float) && hasSameDirection(Vector)).

public boolean
isCollinear(T other)

Returns: true if this vector is collinear with the other vector (isOnLine(Vector) && hasSameDirection(Vector)).

public boolean
isCollinearOpposite(T other, float epsilon)

Returns: true if this vector is opposite collinear with the other vector (isOnLine(Vector, float) && hasOppositeDirection(Vector)).

public boolean
isCollinearOpposite(T other)

Returns: true if this vector is opposite collinear with the other vector (isOnLine(Vector) && hasOppositeDirection(Vector)).

public 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)

public boolean
isOnLine(T other)

Returns: true if this vector is in line with the other vector (either in the same or the opposite direction)

public boolean
isPerpendicular(T other)

Returns: Whether this vector is perpendicular with the other vector.

public boolean
isPerpendicular(T other, float
a positive small number close to zero
epsilon
)

Returns: Whether this vector is perpendicular with the other vector.

public boolean
isUnit()

Returns: Whether this vector is a unit length vector

public boolean
isUnit(final float margin)

Returns: Whether this vector is a unit length vector within the given margin.

public boolean
isZero()

Returns: Whether this vector is a zero vector

public boolean
isZero(final float margin)

Returns: Whether the length of this vector is smaller than the given margin

public float
len()

Returns: The Euclidean length

public float

Returns:

The squared Euclidean length
len2
()

This method is faster than Vector#len() because it avoids calculating a square root.

public T

Returns:

This vector for chaining.
lerp
(T
The target vector
target
,
float
The interpolation coefficient
alpha
)

Linearly interpolates between this vector and the target vector by alpha which is in the range [0,1].

public T

Returns:

this vector for chaining
limit
(float
desired maximum length for this vector
limit
)

Limits the length of this vector, based on the desired maximum length.

public T

Returns:

this vector for chaining
limit2
(float
squared desired maximum length for this vector
limit2
)

Limits the length of this vector, based on the desired maximum length squared.

public T
mulAdd(T
addition vector
v
,
float
for scaling the addition vector
scalar
)

First scale a supplied vector, then add it to this vector.

public T
mulAdd(T
addition vector
v
,
T
vector by whose values the addition vector will be scaled
mulVec
)

First scale a supplied vector, then add it to this vector.

public T

Returns:

This vector for chaining
nor
()

Normalizes this vector.

public T

Returns:

This vector for chaining
scl
(float
The scalar
scalar
)

Scales this vector by a scalar

public T

Returns:

This vector for chaining
scl
(T v)

Scales this vector by another vector

public T

Returns:

This vector for chaining
set
(T
The vector
v
)

Sets this vector from the given vector

public T

Returns:

this vector for chaining
setLength
(float
desired length for this vector
len
)

Sets the length of this vector.

public T

Returns:

this vector for chaining
setLength2
(float
desired square of the length for this vector
len2
)

Sets the length of this vector, based on the square of the desired length.

public T

Returns:

This vector for chaining
setToRandomDirection
()

Sets this vector to the unit vector with a random direction

public T

Returns:

This vector for chaining
setZero
()

Sets the components of this vector to 0

public T

Returns:

This vector for chaining
sub
(T
The vector
v
)

Subtracts the given vector from this vector.

Method Detail

addback to summary
public T add(T v)

Adds the given vector to this vector

Parameters
v:T

The vector

Returns:T

This vector for chaining

clampback to summary
public T clamp(float min, float max)

Clamps this vector's length to given min and max values

Parameters
min:float

Min length

max:float

Max length

Returns:T

This vector for chaining

cpyback to summary
public T cpy()
Returns:T

a copy of this vector

dotback to summary
public float dot(T v)
Parameters
v:T

The other vector

Returns:float

The dot product between this and the other vector

dstback to summary
public float dst(T v)
Parameters
v:T

The other vector

Returns:float

the distance between this and the other vector

dst2back to summary
public float dst2(T v)

This method is faster than Vector#dst(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:T

The other vector

Returns:float

the squared distance between this and the other vector

epsilonEqualsback to summary
public boolean epsilonEquals(T other, float epsilon)

Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.

Returns:boolean

whether the vectors have fuzzy equality.

hasOppositeDirectionback to summary
public boolean hasOppositeDirection(T other)
Returns:boolean

Whether this vector has opposite direction compared to the other vector. True if the normalized dot product is < 0.

hasSameDirectionback to summary
public boolean hasSameDirection(T other)
Returns:boolean

Whether this vector has similar direction compared to the other vector. True if the normalized dot product is > 0.

interpolateback to summary
public 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:T

The target vector

alpha:float

The interpolation coefficient

interpolator:Interpolation

An Interpolation object describing the used interpolation method

Returns:T

This vector for chaining.

isCollinearback to summary
public boolean isCollinear(T other, float epsilon)
Returns:boolean

true if this vector is collinear with the other vector (isOnLine(Vector, float) && hasSameDirection(Vector)).

isCollinearback to summary
public boolean isCollinear(T other)
Returns:boolean

true if this vector is collinear with the other vector (isOnLine(Vector) && hasSameDirection(Vector)).

isCollinearOppositeback to summary
public boolean isCollinearOpposite(T other, float epsilon)
Returns:boolean

true if this vector is opposite collinear with the other vector (isOnLine(Vector, float) && hasOppositeDirection(Vector)).

isCollinearOppositeback to summary
public boolean isCollinearOpposite(T other)
Returns:boolean

true if this vector is opposite collinear with the other vector (isOnLine(Vector) && hasOppositeDirection(Vector)).

isOnLineback to summary
public boolean isOnLine(T other, float epsilon)
Returns:boolean

true if this vector is in line with the other vector (either in the same or the opposite direction)

isOnLineback to summary
public boolean isOnLine(T other)
Returns:boolean

true if this vector is in line with the other vector (either in the same or the opposite direction)

isPerpendicularback to summary
public boolean isPerpendicular(T other)
Returns:boolean

Whether this vector is perpendicular with the other vector. True if the dot product is 0.

isPerpendicularback to summary
public boolean isPerpendicular(T other, float epsilon)
Parameters
epsilon:float

a positive small number close to zero

Returns:boolean

Whether this vector is perpendicular with the other vector. True if the dot product is 0.

isUnitback to summary
public boolean isUnit()
Returns:boolean

Whether this vector is a unit length vector

isUnitback to summary
public boolean isUnit(final float margin)
Returns:boolean

Whether this vector is a unit length vector within the given margin.

isZeroback to summary
public boolean isZero()
Returns:boolean

Whether this vector is a zero vector

isZeroback to summary
public boolean isZero(final float margin)
Returns:boolean

Whether the length of this vector is smaller than the given margin

lenback to summary
public float len()
Returns:float

The Euclidean length

len2back to summary
public float len2()

This method is faster than Vector#len() 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:float

The squared Euclidean length

lerpback to summary
public 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:T

The target vector

alpha:float

The interpolation coefficient

Returns:T

This vector for chaining.

limitback to summary
public T limit(float limit)

Limits the length of this vector, based on the desired maximum length.

Parameters
limit:float

desired maximum length for this vector

Returns:T

this vector for chaining

limit2back to summary
public 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:float

squared desired maximum length for this vector

Returns:T

this vector for chaining

See Also
len2()
mulAddback to summary
public T mulAdd(T v, float scalar)

First scale a supplied vector, then add it to this vector.

Parameters
v:T

addition vector

scalar:float

for scaling the addition vector

mulAddback to summary
public T mulAdd(T v, T mulVec)

First scale a supplied vector, then add it to this vector.

Parameters
v:T

addition vector

mulVec:T

vector by whose values the addition vector will be scaled

norback to summary
public T nor()

Normalizes this vector. Does nothing if it is zero.

Returns:T

This vector for chaining

sclback to summary
public T scl(float scalar)

Scales this vector by a scalar

Parameters
scalar:float

The scalar

Returns:T

This vector for chaining

sclback to summary
public T scl(T v)

Scales this vector by another vector

Returns:T

This vector for chaining

setback to summary
public T set(T v)

Sets this vector from the given vector

Parameters
v:T

The vector

Returns:T

This vector for chaining

setLengthback to summary
public T setLength(float len)

Sets the length of this vector. Does nothing if this vector is zero.

Parameters
len:float

desired length for this vector

Returns:T

this vector for chaining

setLength2back to summary
public 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:float

desired square of the length for this vector

Returns:T

this vector for chaining

See Also
len2()
setToRandomDirectionback to summary
public T setToRandomDirection()

Sets this vector to the unit vector with a random direction

Returns:T

This vector for chaining

setZeroback to summary
public T setZero()

Sets the components of this vector to 0

Returns:T

This vector for chaining

subback to summary
public T sub(T v)

Subtracts the given vector from this vector.

Parameters
v:T

The vector

Returns:T

This vector for chaining