# Vector2

data class Vector2(x: Double, y: Double) : LinearType<Vector2>

Double-precision 2D vector.

## Constructors

Vector2
fun Vector2(x: Double)
Vector2
fun Vector2(x: Double, y: Double)

Companion
object Companion

## Functions

cross
infix fun cross(right: Vector2): Double

Calculates a cross product between this Vector2 and right.

distanceTo
fun distanceTo(other: Vector2): Double

Calculates the Euclidean distance to other.

div
open operator override fun div(scale: Double): Vector2
operator fun div(d: Vector2): Vector2
dot
infix fun dot(right: Vector2): Double

Calculates a dot product between this Vector2 and right.

get
operator fun get(i: Int): Double
minus
operator fun minus(d: Double): Vector2
open operator override fun minus(right: Vector2): Vector2
mix
fun mix(o: Vector2, mix: Double): Vector2
perpendicular
fun perpendicular(polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): Vector2

Calculates a vector perpendicular to the current one.

plus
operator fun plus(d: Double): Vector2
open operator override fun plus(right: Vector2): Vector2
reflect
infix fun reflect(surfaceNormal: Vector2): Vector2
rotate
fun rotate(degrees: Double, origin: Vector2 = ZERO): Vector2

Creates a new Vector2 with the given rotation and origin.

squaredDistanceTo
fun squaredDistanceTo(other: Vector2): Double

Calculates the squared Euclidean distance to other.

times
open operator override fun times(scale: Double): Vector2
operator fun times(v: Vector2): Vector2
toDoubleArray
fun toDoubleArray(): DoubleArray

Casts to DoubleArray.

toInt
fun toInt(): IntVector2

Casts to IntVector2.

unaryMinus
operator fun unaryMinus(): Vector2
vector3
fun vector3(x: Double = this.x, y: Double = this.y, z: Double = 0.0): Vector3

Upcasts to Vector3.

vector4
fun vector4(x: Double = this.x, y: Double = this.y, z: Double = 0.0, w: Double = 0.0): Vector4

Upcasts to Vector4.

## Properties

length
val length: Double

The Euclidean length of the vector.

normalized
val normalized: Vector2

Returns a normalized version of the vector. (i.e. unit vector)

squaredLength
val squaredLength: Double

The squared Euclidean length of the vector.

x
val x: Double
xx
val xx: Vector2
xy0
val xy0: Vector3
xy00
val xy00: Vector4
xy01
val xy01: Vector4
xy1
val xy1: Vector3
y
val y: Double
yx
val yx: Vector2
yy
val yy: Vector2

## Extensions

clamp
fun Vector2.clamp(min: Vector2, max: Vector2): Vector2

Returns Vector2 whose value is limited between min and max per vector component.

map