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

public Class Vector2

extends Object
implements Serializable, Vector<Vector2>
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.math.Vector, java.io.Serializable
Imports
java.io.Serializable, com.badlogic.gdx.utils.GdxRuntimeException, .NumberUtils

Encapsulates a 2D vector. Allows chaining methods by returning a reference to itself
Author
[email protected]

Field Summary

Modifier and TypeField and Description
public static final Vector2
private static final long
public static final Vector2
X

public float
x

the x-component of this vector

public static final Vector2
Y

public float
y

the y-component of this vector

public static final Vector2

Constructor Summary

AccessConstructor and Description
public
Vector2()

Constructs a new vector at (0,0)

public
Vector2(float
The x-component
x
,
float
The y-component
y
)

Constructs a vector with the given components

public
Vector2(Vector2
The vector
v
)

Constructs a vector from the given vector

Method Summary

Modifier and TypeMethod and Description
public Vector2
add(Vector2 v)

Implements com.badlogic.gdx.math.Vector.add.

Adds the given vector to this vector

public Vector2

Returns:

This vector for chaining
add
(float
The x-component
x
,
float
The y-component
y
)

Adds the given components to this vector

public float
angle()
Deprecated use angleDeg() instead.

Returns: the angle in degrees of this vector (point) relative to the x-axis.

public float
angle(Vector2 reference)
Deprecated use angleDeg(Vector2) instead. Beware of the changes in returned angle to counter-clockwise and the range.

Returns: the angle in degrees of this vector (point) relative to the given vector.

public float
angleDeg()

Returns: the angle in degrees of this vector (point) relative to the x-axis.

public float
angleDeg(Vector2 reference)

Returns: the angle in degrees of this vector (point) relative to the given vector.

public static float
angleDeg(float x, float y)

Returns: the angle in degrees of this vector (point) relative to the x-axis.

public float
angleRad()

Returns: the angle in radians of this vector (point) relative to the x-axis.

public float
angleRad(Vector2 reference)

Returns: the angle in radians of this vector (point) relative to the given vector.

public static float
angleRad(float x, float y)

Returns: the angle in radians of this vector (point) relative to the x-axis.

public Vector2
clamp(float min, float max)

Implements com.badlogic.gdx.math.Vector.clamp.

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

public Vector2
public float

Returns:

the cross product
crs
(Vector2
the other vector
v
)

Calculates the 2D cross product between this and the given vector.

public float

Returns:

the cross product
crs
(float
the x-coordinate of the other vector
x
,
float
the y-coordinate of the other vector
y
)

Calculates the 2D cross product between this and the given vector.

public static float
dot(float x1, float y1, float x2, float y2)

public float
public float
dot(float ox, float oy)

public static float
dst(float x1, float y1, float x2, float y2)

public float
public float
dst(float
The x-component of the other vector
x
,
float
The y-component of the other vector
y
)

Returns: the distance between this and the other vector

public static float
dst2(float x1, float y1, float x2, float y2)

public float
dst2(Vector2 v)

Implements com.badlogic.gdx.math.Vector.dst2.

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

public float
dst2(float
The x-component of the other vector
x
,
float
The y-component of the other vector
y
)

Returns: the squared distance between this and the other vector

public boolean
epsilonEquals(Vector2 other, float epsilon)

Implements com.badlogic.gdx.math.Vector.epsilonEquals.

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

public boolean

Returns:

whether the vectors are the same.
epsilonEquals
(float x, float y, float epsilon)

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

public boolean

Returns:

true if vector are equal, otherwise false
epsilonEquals
(final Vector2
other vector to compare
other
)

Compares this vector with the other vector using MathUtils.FLOAT_ROUNDING_ERROR for fuzzy equality testing

public boolean

Returns:

true if vector are equal, otherwise false
epsilonEquals
(float
x component of the other vector to compare
x
,
float
y component of the other vector to compare
y
)

Implements com.badlogic.gdx.math.Vector.epsilonEquals.

Compares this vector with the other vector using MathUtils.FLOAT_ROUNDING_ERROR for fuzzy equality testing

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Vector2

Returns:

this vector for chaining
fromString
(String
the string.
v
)

Sets this Vector2 to the value represented by the specified string according to the format of toString().

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
public boolean
public boolean

Returns:

Whether this and the other vector are equal with exact precision
idt
(final Vector2
The other vector
vector
)

Returns true if this vector and the vector parameter have identical components.

public Vector2
interpolate(Vector2 target, float alpha, Interpolation interpolation)

Implements com.badlogic.gdx.math.Vector.interpolate.

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

public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
isOnLine(Vector2 other, float epsilon)

Implements com.badlogic.gdx.math.Vector.isOnLine.

public boolean
public boolean
public boolean
public boolean
isUnit(final float margin)

Implements com.badlogic.gdx.math.Vector.isUnit.

public boolean
public boolean
isZero(final float margin)

Implements com.badlogic.gdx.math.Vector.isZero.

public static float
len(float x, float y)

public float
public static float
len2(float x, float y)

public float
len2()

Implements com.badlogic.gdx.math.Vector.len2.

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

public Vector2
lerp(Vector2 target, float alpha)

Implements com.badlogic.gdx.math.Vector.lerp.

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

public Vector2
limit(float limit)

Implements com.badlogic.gdx.math.Vector.limit.

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

public Vector2
limit2(float limit2)

Implements com.badlogic.gdx.math.Vector.limit2.

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

public Vector2

Returns:

this vector
mul
(Matrix3
the matrix
mat
)

Left-multiplies this vector by the given matrix

public Vector2
mulAdd(Vector2 vec, float scalar)

Implements com.badlogic.gdx.math.Vector.mulAdd, com.badlogic.gdx.math.Vector.mulAdd.

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

public Vector2
mulAdd(Vector2 vec, Vector2 mulVec)

Implements com.badlogic.gdx.math.Vector.mulAdd.

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

public Vector2
nor()

Implements com.badlogic.gdx.math.Vector.nor.

Normalizes this vector.

public Vector2
rotate(float
the angle in degrees
degrees
)
Deprecated use rotateDeg(float) instead.

Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.

public Vector2
rotate90(int dir)

Rotates the Vector2 by 90 degrees in the specified direction, where >= 0 is counter-clockwise and < 0 is clockwise.

public Vector2
rotateAround(Vector2
center Vector2
reference
,
float
the angle in degrees
degrees
)
Deprecated use rotateAroundDeg(Vector2, float) instead.

Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up.

public Vector2
rotateAroundDeg(Vector2
center Vector2
reference
,
float
the angle in degrees
degrees
)

Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up.

public Vector2
rotateAroundRad(Vector2
center Vector2
reference
,
float
the angle in radians
radians
)

Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up.

public Vector2
rotateDeg(float
the angle in degrees
degrees
)

Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.

public Vector2
rotateRad(float
the angle in radians
radians
)

Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.

public Vector2
scl(float scalar)

Implements com.badlogic.gdx.math.Vector.scl, com.badlogic.gdx.math.Vector.scl.

Scales this vector by a scalar

public Vector2

Returns:

This vector for chaining
scl
(float x, float y)

Multiplies this vector by a scalar

public Vector2
scl(Vector2 v)

Implements com.badlogic.gdx.math.Vector.scl.

Scales this vector by another vector

public Vector2
set(Vector2 v)

Implements com.badlogic.gdx.math.Vector.set.

Sets this vector from the given vector

public Vector2

Returns:

This vector for chaining
set
(float
The x-component
x
,
float
The y-component
y
)

Sets the components of this vector

public Vector2
setAngle(float
The angle in degrees to set.
degrees
)
Deprecated use setAngleDeg(float) instead.

Sets the angle of the vector in degrees relative to the x-axis, towards the positive y-axis (typically counter-clockwise).

public Vector2
setAngleDeg(float
The angle in degrees to set.
degrees
)

Sets the angle of the vector in degrees relative to the x-axis, towards the positive y-axis (typically counter-clockwise).

public Vector2
setAngleRad(float
The angle in radians to set.
radians
)

Sets the angle of the vector in radians relative to the x-axis, towards the positive y-axis (typically counter-clockwise).

public Vector2
setLength(float len)

Implements com.badlogic.gdx.math.Vector.setLength.

Sets the length of this vector.

public Vector2
setLength2(float len2)

Implements com.badlogic.gdx.math.Vector.setLength2.

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

public Vector2
setToRandomDirection()

Implements com.badlogic.gdx.math.Vector.setToRandomDirection.

Sets this vector to the unit vector with a random direction

public Vector2
setZero()

Implements com.badlogic.gdx.math.Vector.setZero.

Sets the components of this vector to 0

public Vector2
sub(Vector2 v)

Implements com.badlogic.gdx.math.Vector.sub.

Subtracts the given vector from this vector.

public Vector2

Returns:

This vector for chaining
sub
(float
The x-component of the other vector
x
,
float
The y-component of the other vector
y
)

Subtracts the other vector from this vector.

public String

Returns:

a string representation of this object.
toString
()

Overrides java.lang.Object.toString.

Converts this Vector2 to a string in the format (x,y).

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

Oneback to summary
public static final Vector2 One
serialVersionUIDback to summary
private static final long serialVersionUID
Xback to summary
public static final Vector2 X
xback to summary
public float x

the x-component of this vector

Yback to summary
public static final Vector2 Y
yback to summary
public float y

the y-component of this vector

Zeroback to summary
public static final Vector2 Zero

Constructor Detail

Vector2back to summary
public Vector2()

Constructs a new vector at (0,0)

Vector2back to summary
public Vector2(float x, float y)

Constructs a vector with the given components

Parameters
x:float

The x-component

y:float

The y-component

Vector2back to summary
public Vector2(Vector2 v)

Constructs a vector from the given vector

Parameters
v:Vector2

The vector

Method Detail

addback to summary
public Vector2 add(Vector2 v)

Implements com.badlogic.gdx.math.Vector.add.

Doc from com.badlogic.gdx.math.Vector.add.

Adds the given vector to this vector

Annotations
@Override
addback to summary
public Vector2 add(float x, float y)

Adds the given components to this vector

Parameters
x:float

The x-component

y:float

The y-component

Returns:Vector2

This vector for chaining

angleback to summary
public float angle()

Deprecated

use angleDeg() instead.

Returns:float

the angle in degrees of this vector (point) relative to the x-axis. Angles are towards the positive y-axis (typically counter-clockwise) and between 0 and 360.

Annotations
@Deprecated
angleback to summary
public float angle(Vector2 reference)

Deprecated

use angleDeg(Vector2) instead. Beware of the changes in returned angle to counter-clockwise and the range.

Returns:float

the angle in degrees of this vector (point) relative to the given vector. Angles are towards the negative y-axis (typically clockwise) between -180 and +180

Annotations
@Deprecated
angleDegback to summary
public float angleDeg()
Returns:float

the angle in degrees of this vector (point) relative to the x-axis. Angles are towards the positive y-axis (typically counter-clockwise) and in the [0, 360) range.

angleDegback to summary
public float angleDeg(Vector2 reference)
Returns:float

the angle in degrees of this vector (point) relative to the given vector. Angles are towards the positive y-axis (typically counter-clockwise.) in the [0, 360) range

angleDegback to summary
public static float angleDeg(float x, float y)
Returns:float

the angle in degrees of this vector (point) relative to the x-axis. Angles are towards the positive y-axis (typically counter-clockwise) and in the [0, 360) range.

angleRadback to summary
public float angleRad()
Returns:float

the angle in radians of this vector (point) relative to the x-axis. Angles are towards the positive y-axis. (typically counter-clockwise)

angleRadback to summary
public float angleRad(Vector2 reference)
Returns:float

the angle in radians of this vector (point) relative to the given vector. Angles are towards the positive y-axis. (typically counter-clockwise.)

angleRadback to summary
public static float angleRad(float x, float y)
Returns:float

the angle in radians of this vector (point) relative to the x-axis. Angles are towards the positive y-axis. (typically counter-clockwise)

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

Implements com.badlogic.gdx.math.Vector.clamp.

Doc from com.badlogic.gdx.math.Vector.clamp.

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

Annotations
@Override
cpyback to summary
public Vector2 cpy()

Implements com.badlogic.gdx.math.Vector.cpy.

Annotations
@Override
crsback to summary
public float crs(Vector2 v)

Calculates the 2D cross product between this and the given vector.

Parameters
v:Vector2

the other vector

Returns:float

the cross product

crsback to summary
public float crs(float x, float y)

Calculates the 2D cross product between this and the given vector.

Parameters
x:float

the x-coordinate of the other vector

y:float

the y-coordinate of the other vector

Returns:float

the cross product

dotback to summary
public static float dot(float x1, float y1, float x2, float y2)
dotback to summary
public float dot(Vector2 v)

Implements com.badlogic.gdx.math.Vector.dot.

Annotations
@Override
dotback to summary
public float dot(float ox, float oy)
dstback to summary
public static float dst(float x1, float y1, float x2, float y2)
dstback to summary
public float dst(Vector2 v)

Implements com.badlogic.gdx.math.Vector.dst.

Annotations
@Override
dstback to summary
public float dst(float x, float y)
Parameters
x:float

The x-component of the other vector

y:float

The y-component of the other vector

Returns:float

the distance between this and the other vector

dst2back to summary
public static float dst2(float x1, float y1, float x2, float y2)
dst2back to summary
public float dst2(Vector2 v)

Implements com.badlogic.gdx.math.Vector.dst2.

Doc from com.badlogic.gdx.math.Vector.dst2.

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.

Annotations
@Override
dst2back to summary
public float dst2(float x, float y)
Parameters
x:float

The x-component of the other vector

y:float

The y-component of the other vector

Returns:float

the squared distance between this and the other vector

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

Implements com.badlogic.gdx.math.Vector.epsilonEquals.

Doc from com.badlogic.gdx.math.Vector.epsilonEquals.

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

Annotations
@Override
epsilonEqualsback to summary
public boolean epsilonEquals(float x, float y, float epsilon)

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

Returns:boolean

whether the vectors are the same.

epsilonEqualsback to summary
public boolean epsilonEquals(final Vector2 other)

Compares this vector with the other vector using MathUtils.FLOAT_ROUNDING_ERROR for fuzzy equality testing

Parameters
other:Vector2

other vector to compare

Returns:boolean

true if vector are equal, otherwise false

epsilonEqualsback to summary
public boolean epsilonEquals(float x, float y)

Implements com.badlogic.gdx.math.Vector.epsilonEquals.

Compares this vector with the other vector using MathUtils.FLOAT_ROUNDING_ERROR for fuzzy equality testing

Parameters
x:float

x component of the other vector to compare

y:float

y component of the other vector to compare

Returns:boolean

true if vector are equal, otherwise false

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
fromStringback to summary
public Vector2 fromString(String v)

Sets this Vector2 to the value represented by the specified string according to the format of toString().

Parameters
v:String

the string.

Returns:Vector2

this vector for chaining

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
hasOppositeDirectionback to summary
public boolean hasOppositeDirection(Vector2 vector)

Implements com.badlogic.gdx.math.Vector.hasOppositeDirection.

Annotations
@Override
hasSameDirectionback to summary
public boolean hasSameDirection(Vector2 vector)

Implements com.badlogic.gdx.math.Vector.hasSameDirection.

Annotations
@Override
idtback to summary
public boolean idt(final Vector2 vector)

Returns true if this vector and the vector parameter have identical components.

Parameters
vector:Vector2

The other vector

Returns:boolean

Whether this and the other vector are equal with exact precision

interpolateback to summary
public Vector2 interpolate(Vector2 target, float alpha, Interpolation interpolation)

Implements com.badlogic.gdx.math.Vector.interpolate.

Doc from com.badlogic.gdx.math.Vector.interpolate.

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.

Annotations
@Override
isCollinearback to summary
public boolean isCollinear(Vector2 other, float epsilon)

Implements com.badlogic.gdx.math.Vector.isCollinear.

Annotations
@Override
isCollinearback to summary
public boolean isCollinear(Vector2 other)

Implements com.badlogic.gdx.math.Vector.isCollinear.

Annotations
@Override
isCollinearOppositeback to summary
public boolean isCollinearOpposite(Vector2 other, float epsilon)

Implements com.badlogic.gdx.math.Vector.isCollinearOpposite.

Annotations
@Override
isCollinearOppositeback to summary
public boolean isCollinearOpposite(Vector2 other)

Implements com.badlogic.gdx.math.Vector.isCollinearOpposite.

Annotations
@Override
isOnLineback to summary
public boolean isOnLine(Vector2 other)

Implements com.badlogic.gdx.math.Vector.isOnLine.

Annotations
@Override
isOnLineback to summary
public boolean isOnLine(Vector2 other, float epsilon)

Implements com.badlogic.gdx.math.Vector.isOnLine.

Annotations
@Override
isPerpendicularback to summary
public boolean isPerpendicular(Vector2 vector)

Implements com.badlogic.gdx.math.Vector.isPerpendicular.

Annotations
@Override
isPerpendicularback to summary
public boolean isPerpendicular(Vector2 vector, float epsilon)

Implements com.badlogic.gdx.math.Vector.isPerpendicular.

Annotations
@Override
isUnitback to summary
public boolean isUnit()

Implements com.badlogic.gdx.math.Vector.isUnit.

Annotations
@Override
isUnitback to summary
public boolean isUnit(final float margin)

Implements com.badlogic.gdx.math.Vector.isUnit.

Annotations
@Override
isZeroback to summary
public boolean isZero()

Implements com.badlogic.gdx.math.Vector.isZero.

Annotations
@Override
isZeroback to summary
public boolean isZero(final float margin)

Implements com.badlogic.gdx.math.Vector.isZero.

Annotations
@Override
lenback to summary
public static float len(float x, float y)
lenback to summary
public float len()

Implements com.badlogic.gdx.math.Vector.len.

Annotations
@Override
len2back to summary
public static float len2(float x, float y)
len2back to summary
public float len2()

Implements com.badlogic.gdx.math.Vector.len2.

Doc from com.badlogic.gdx.math.Vector.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.

Annotations
@Override
lerpback to summary
public Vector2 lerp(Vector2 target, float alpha)

Implements com.badlogic.gdx.math.Vector.lerp.

Doc from com.badlogic.gdx.math.Vector.lerp.

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.

Annotations
@Override
limitback to summary
public Vector2 limit(float limit)

Implements com.badlogic.gdx.math.Vector.limit.

Doc from com.badlogic.gdx.math.Vector.limit.

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

Annotations
@Override
limit2back to summary
public Vector2 limit2(float limit2)

Implements com.badlogic.gdx.math.Vector.limit2.

Doc from com.badlogic.gdx.math.Vector.limit2.

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

This method is slightly faster than limit().

Annotations
@Override
mulback to summary
public Vector2 mul(Matrix3 mat)

Left-multiplies this vector by the given matrix

Parameters
mat:Matrix3

the matrix

Returns:Vector2

this vector

mulAddback to summary
public Vector2 mulAdd(Vector2 vec, float scalar)

Implements com.badlogic.gdx.math.Vector.mulAdd, com.badlogic.gdx.math.Vector.mulAdd.

Doc from com.badlogic.gdx.math.Vector.mulAdd.

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

Annotations
@Override
mulAddback to summary
public Vector2 mulAdd(Vector2 vec, Vector2 mulVec)

Implements com.badlogic.gdx.math.Vector.mulAdd.

Doc from com.badlogic.gdx.math.Vector.mulAdd.

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

Annotations
@Override
norback to summary
public Vector2 nor()

Implements com.badlogic.gdx.math.Vector.nor.

Doc from com.badlogic.gdx.math.Vector.nor.

Normalizes this vector. Does nothing if it is zero.

Annotations
@Override
rotateback to summary
public Vector2 rotate(float degrees)

Deprecated

use rotateDeg(float) instead.

Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.

Parameters
degrees:float

the angle in degrees

Annotations
@Deprecated
rotate90back to summary
public Vector2 rotate90(int dir)

Rotates the Vector2 by 90 degrees in the specified direction, where >= 0 is counter-clockwise and < 0 is clockwise.

rotateAroundback to summary
public Vector2 rotateAround(Vector2 reference, float degrees)

Deprecated

use rotateAroundDeg(Vector2, float) instead.

Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up.

Parameters
reference:Vector2

center Vector2

degrees:float

the angle in degrees

Annotations
@Deprecated
rotateAroundDegback to summary
public Vector2 rotateAroundDeg(Vector2 reference, float degrees)

Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up.

Parameters
reference:Vector2

center Vector2

degrees:float

the angle in degrees

rotateAroundRadback to summary
public Vector2 rotateAroundRad(Vector2 reference, float radians)

Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up.

Parameters
reference:Vector2

center Vector2

radians:float

the angle in radians

rotateDegback to summary
public Vector2 rotateDeg(float degrees)

Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.

Parameters
degrees:float

the angle in degrees

rotateRadback to summary
public Vector2 rotateRad(float radians)

Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.

Parameters
radians:float

the angle in radians

sclback to summary
public Vector2 scl(float scalar)

Implements com.badlogic.gdx.math.Vector.scl, com.badlogic.gdx.math.Vector.scl.

Doc from com.badlogic.gdx.math.Vector.scl.

Scales this vector by a scalar

Annotations
@Override
sclback to summary
public Vector2 scl(float x, float y)

Multiplies this vector by a scalar

Returns:Vector2

This vector for chaining

sclback to summary
public Vector2 scl(Vector2 v)

Implements com.badlogic.gdx.math.Vector.scl.

Doc from com.badlogic.gdx.math.Vector.scl.

Scales this vector by another vector

Annotations
@Override
setback to summary
public Vector2 set(Vector2 v)

Implements com.badlogic.gdx.math.Vector.set.

Doc from com.badlogic.gdx.math.Vector.set.

Sets this vector from the given vector

Annotations
@Override
setback to summary
public Vector2 set(float x, float y)

Sets the components of this vector

Parameters
x:float

The x-component

y:float

The y-component

Returns:Vector2

This vector for chaining

setAngleback to summary
public Vector2 setAngle(float degrees)

Deprecated

use setAngleDeg(float) instead.

Sets the angle of the vector in degrees relative to the x-axis, towards the positive y-axis (typically counter-clockwise).

Parameters
degrees:float

The angle in degrees to set.

Annotations
@Deprecated
setAngleDegback to summary
public Vector2 setAngleDeg(float degrees)

Sets the angle of the vector in degrees relative to the x-axis, towards the positive y-axis (typically counter-clockwise).

Parameters
degrees:float

The angle in degrees to set.

setAngleRadback to summary
public Vector2 setAngleRad(float radians)

Sets the angle of the vector in radians relative to the x-axis, towards the positive y-axis (typically counter-clockwise).

Parameters
radians:float

The angle in radians to set.

setLengthback to summary
public Vector2 setLength(float len)

Implements com.badlogic.gdx.math.Vector.setLength.

Doc from com.badlogic.gdx.math.Vector.setLength.

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

Annotations
@Override
setLength2back to summary
public Vector2 setLength2(float len2)

Implements com.badlogic.gdx.math.Vector.setLength2.

Doc from com.badlogic.gdx.math.Vector.setLength2.

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().

Annotations
@Override
setToRandomDirectionback to summary
public Vector2 setToRandomDirection()

Implements com.badlogic.gdx.math.Vector.setToRandomDirection.

Doc from com.badlogic.gdx.math.Vector.setToRandomDirection.

Sets this vector to the unit vector with a random direction

Annotations
@Override
setZeroback to summary
public Vector2 setZero()

Implements com.badlogic.gdx.math.Vector.setZero.

Doc from com.badlogic.gdx.math.Vector.setZero.

Sets the components of this vector to 0

Annotations
@Override
subback to summary
public Vector2 sub(Vector2 v)

Implements com.badlogic.gdx.math.Vector.sub.

Doc from com.badlogic.gdx.math.Vector.sub.

Subtracts the given vector from this vector.

Annotations
@Override
subback to summary
public Vector2 sub(float x, float y)

Subtracts the other vector from this vector.

Parameters
x:float

The x-component of the other vector

y:float

The y-component of the other vector

Returns:Vector2

This vector for chaining

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Converts this Vector2 to a string in the format (x,y).

Returns:String

a string representation of this object.

Annotations
@Override