Companion

object Companion

The companion object of Vector2.

Properties

Link copied to clipboard
@JvmField
val DOWN: Vector2

The down Vector2 instance, and its real value is (0f, -1f).

Link copied to clipboard
@JvmField
val LEFT: Vector2

The left Vector2 instance, and its real value is (-1f, 0f).

Link copied to clipboard
@JvmField
val ONE: Vector2

A constant representing a vector with all components set to one (1, 1).

Link copied to clipboard
@JvmField
val RIGHT: Vector2

The right Vector2 instance, and its real value is (1f, 0f).

Link copied to clipboard
@JvmField
val UP: Vector2

The up Vector2 instance, and its real value is (0f, 1f).

Link copied to clipboard
@JvmField
val ZERO: Vector2

A constant representing a zero vector (0, 0).

Functions

Link copied to clipboard
@JvmStatic
fun angle(from: Vector2, to: Vector2): Float

Calculates the angle between two 2D vectors and returns it in degrees. This version includes robustness improvements for numerical stability. This function throws an IllegalArgumentException if either input vector is a zero vector. The calculated angle represents the shortest angle between the two vectors and is typically in the range [0, 180] degrees.

Link copied to clipboard
@JvmStatic
fun cross(a: Vector2, b: Vector2): Float

Calculates the 2D cross product (also known as the perpendicular dot product or z-component of the 3D cross product) of two 2D vectors.

Link copied to clipboard
@JvmStatic
fun distance(a: Vector2, b: Vector2): Float

Calculates the Euclidean distance between two 2D points (represented by vectors).

Link copied to clipboard
@JvmStatic
fun dot(a: Vector2, b: Vector2): Float

Calculates the dot product (scalar product) of two 2D vectors.

Link copied to clipboard
@JvmStatic
fun faceForward(n: Vector2, i: Vector2, nRef: Vector2): Vector2

Orients a normal vector n to face towards an incident vector i, using a reference normal nRef to determine the orientation.

Link copied to clipboard
@JvmStatic
fun lerp(a: Vector2, b: Vector2, t: Float): Vector2

Performs linear interpolation between two 2D vectors, a and b.

Link copied to clipboard
@JvmStatic
fun lerpUnclamped(a: Vector2, b: Vector2, t: Float): Vector2

Performs unclamped linear interpolation between two 2D vectors, a and b.

Link copied to clipboard
@JvmStatic
fun moveTowards(current: Vector2, target: Vector2, maxDistanceDeltaInput: Float): Vector2

Moves a point current towards a target point by a maximum distance.

Link copied to clipboard
@JvmStatic
fun project(a: Vector2, b: Vector2): Vector2

Calculates the vector projection of vector a onto vector b.

Link copied to clipboard
@JvmStatic
fun reflect(i: Vector2, n: Vector2): Vector2

Calculates the reflection of an incident vector 'i' across a surface defined by its normal 'n'.