API reference
API reference
Select your platform
No SDKs available
No versions available

Vector2

Vector2

data class Vector2(var x: Float = 0.0f, var y: Float = 0.0f)
Represents a 2D vector with x and y components.
Parameters
JVM
NameSummary
x
The x component of the vector.
y
The y component of the vector.

Constructors

NameSummary
Vector2
constructor(v: Float)
Secondary constructor to create a vector where both components are the same.
constructor(x: Float = 0.0f, y: Float = 0.0f)

Properties

NameSummary
x
var x: Float
y
var y: Float

Functions

NameSummary
add
fun add(v: Vector2): Vector2
Adds the specified vector to this vector.
cross
fun cross(other: Vector2): Float
Calculates the cross product of this vector with another vector.
distanceTo
fun distanceTo(v: Vector2): Float
Calculates the distance to another vector.
div
operator fun div(v: Float): Vector2
Divides each component of this vector by a scalar.
divide
fun divide(v: Float): Vector2
Divides each component of this vector by a scalar.
dot
fun dot(v: Vector2): Float
Calculates the dot product of this vector with another vector.
length
fun length(): Float
Returns the length (magnitude) of this vector.
lerp
fun lerp(dest: Vector2, ratio: Float): Vector2
Linearly interpolates between this vector and another vector by the given ratio.
minus
operator fun minus(v: Vector2): Vector2
Subtracts the other vector from this vector.
multiply
fun multiply(v: Vector2): Vector2
Multiplies this vector by another vector component-wise.
fun multiply(v: Float): Vector2
Multiplies each component of this vector by a scalar.
negate
fun negate(): Vector2
Negates this vector.
normalize
fun normalize(): Vector2
Normalizes this vector.
plus
operator fun plus(v: Vector2): Vector2
Adds two vectors.
setX
fun setX(x: Float): Vector2
Sets the x component of this vector.
setY
fun setY(y: Float): Vector2
Sets the y component of this vector.
sub
fun sub(v: Vector2): Vector2
Subtracts the specified vector from this vector.
times
operator fun times(v: Vector2): Vector2
Multiplies two vectors component-wise.
operator fun times(v: Float): Vector2
Multiplies each component of this vector by a scalar.
toString
open override fun toString(): String
Returns a string representation of the vector.
unaryMinus
operator fun unaryMinus(): Vector2
Negates this vector.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon