openrndr / org.openrndr.math / Vector2

# Vector2

`data class Vector2 : Serializable, LinearType<Vector2>` (source)

Double precision vector 2

### Constructors

#### <init>

`Vector2(x: Double)`

Double precision vector 2

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

### Properties

#### length

the Euclidean length of the vector

`val length: Double`

#### normalized

a normalized version of the vector

`val normalized: Vector2`

#### squaredLength

the squared Euclidean length of the vector

`val squaredLength: Double`

#### 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`

### Functions

#### cross

calculate cross product between this Vector2 and right

`infix fun cross(right: Vector2): Double`

#### distanceTo

calculate the Euclidean distance to other

`fun distanceTo(other: Vector2): Double`

#### div

`operator fun div(d: Double): Vector2`
`operator fun div(d: Vector2): Vector2`

#### dot

calculate dot product between this Vector2 and right

`infix fun dot(right: Vector2): Double`

#### get

`operator fun get(i: Int): Double`

#### minus

`operator fun minus(vector2: Vector2): Vector2`
`operator fun minus(d: Double): Vector2`

#### mix

`fun mix(o: Vector2, mix: Double): Vector2`

#### perpendicular

calculate perpendicular vector

`fun perpendicular(polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): Vector2`

#### plus

`operator fun plus(vector2: Vector2): Vector2`
`operator fun plus(d: Double): Vector2`

#### reflect

`infix fun reflect(surfaceNormal: Vector2): Vector2`

#### rotate

calculate rotation of Vector2

`fun rotate(degrees: Double, origin: Vector2 = ZERO): Vector2`

#### squaredDistanceTo

calculate the squared Euclidean distance to other

`fun squaredDistanceTo(other: Vector2): Double`

#### times

`operator fun times(d: Double): Vector2`
`operator fun times(v: Vector2): Vector2`

#### toDoubleArray

convert to DoubleArray

`fun toDoubleArray(): DoubleArray`

#### toInt

convert to IntVector2

`fun toInt(): IntVector2`

#### unaryMinus

`operator fun unaryMinus(): Vector2`

#### vector3

upcast to Vector3

`fun vector3(x: Double = this.x, y: Double = this.y, z: Double = 0.0): Vector3`

#### vector4

upcast to Vector4

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

### Companion Object Properties

#### INFINITY

a Vector2 representation for infinite values

`val INFINITY: Vector2`

#### ONE

`val ONE: Vector2`

#### UNIT_X

`val UNIT_X: Vector2`

#### UNIT_Y

`val UNIT_Y: Vector2`

#### ZERO

`val ZERO: Vector2`

### Companion Object Functions

#### fromPolar

`fun fromPolar(polar: Polar): Vector2`

### Extension Functions

#### clamp

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

#### map

`fun Vector2.map(beforeLeft: Vector2, beforeRight: Vector2, afterLeft: Vector2, afterRight: Vector2, clamp: Boolean = false): Vector2`

#### mod

`fun Vector2.mod(b: Vector2): Vector2`

#### saturate

`fun Vector2.saturate(): Vector2`

#### smoothstep

`fun Vector2.smoothstep(edge0: Vector2, edge1: Vector2): Vector2`