# Vector2

Artifact: [androidx.xr.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/xr-runtime) [View Source](https://cs.android.com/search?q=file:androidx/xr/runtime/math/Vector2.kt+class:androidx.xr.runtime.math.Vector2) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

*** ** * ** ***


```
class Vector2
```

<br />

*** ** * ** ***

Position in the 2D plane.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#abs(androidx.xr.runtime.math.Vector2)(vector: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns the absolute values of each component of the vector. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#angularDistance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)(vector1: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2, vector2: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns the angle between this `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#angularDistance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)` and `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#angularDistance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#distance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)(vector1: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2, vector2: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns the distance between `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#distance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)` and `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#distance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#lerp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2,kotlin.Float)(start: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2, end: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2, ratio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a new vector linearly interpolated between `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#lerp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2,kotlin.Float)` and `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#lerp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2,kotlin.Float)` by `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#lerp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2,kotlin.Float)`. |

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#Down()` Vector with y set to negative one and all other components set to zero. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#Left()` Vector with x set to negative one and all other components set to zero. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#One()` Vector with all components set to one. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#Right()` Vector with x set to one and all other components set to zero. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#Up()` Vector with y set to one and all other components set to zero. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#Zero()` Vector with all components set to zero. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#Vector2(androidx.xr.runtime.math.Vector2)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Creates a new vector with the same values as the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#(androidx.xr.runtime.math.Vector2)` vector. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#Vector2(kotlin.Float,kotlin.Float)(x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#clamp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)(min: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2, max: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns a new vector with the values clamped between `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#clamp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)` and `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#clamp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)` vectors. |
| `inline https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#copy(kotlin.Float,kotlin.Float)(x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a copy of the vector. |
| `inline infix https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#cross(androidx.xr.runtime.math.Vector2)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns the cross product of this vector and the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#cross(androidx.xr.runtime.math.Vector2)` vector. |
| `inline operator https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#div(kotlin.Float)(c: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a new vector with this vector divided by a scalar amount. |
| `inline infix https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#dot(androidx.xr.runtime.math.Vector2)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns the dot product of this vector and the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#dot(androidx.xr.runtime.math.Vector2)` vector. |
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` Returns true if this vector is equal to the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#equals(kotlin.Any)`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#hashCode()()` |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#inverse()()` Returns the component-wise multiplicative inverse of this vector. |
| `inline operator https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#minus(androidx.xr.runtime.math.Vector2)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns a new vector with the difference of this vector and the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#minus(androidx.xr.runtime.math.Vector2)` vector. |
| `operator https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#plus(androidx.xr.runtime.math.Vector2)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns a new vector with the sum of this vector and the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#plus(androidx.xr.runtime.math.Vector2)` vector. |
| `inline https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#scale(androidx.xr.runtime.math.Vector2)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2)` Returns a new vector by component-wise multiplying this vector by `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#scale(androidx.xr.runtime.math.Vector2)`. |
| `inline operator https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#times(kotlin.Float)(c: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a new vector multiplied by a scalar amount. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#toNormalized()()` Returns a normalized version of this vector. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#toString()()` |
| `inline operator https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#unaryMinus()()` Negates the values of this vector. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#length()` The length of the vector. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#lengthSquared()` The squared length of the vector. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#x()` the x component of the vector |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#y()` the y component of the vector |

## Public companion functions

### abs

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun abs(vector: Vector2): Vector2
```

Returns the absolute values of each component of the vector.

| Parameters |
|---|---|
| `vector: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the vector to get the absolute values of |

### angularDistance

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun angularDistance(vector1: Vector2, vector2: Vector2): Float
```

Returns the angle between this `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#angularDistance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)` and `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#angularDistance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)`.

| Parameters |
|---|---|
| `vector1: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the first vector |
| `vector2: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the second vector |

### distance

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun distance(vector1: Vector2, vector2: Vector2): Float
```

Returns the distance between `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#distance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)` and `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#distance(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)`.

| Parameters |
|---|---|
| `vector1: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the first vector |
| `vector2: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the second vector |

### lerp

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun lerp(start: Vector2, end: Vector2, ratio: Float): Vector2
```

Returns a new vector linearly interpolated between `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#lerp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2,kotlin.Float)` and `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#lerp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2,kotlin.Float)` by `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#lerp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2,kotlin.Float)`.

If `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2.Companion#lerp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2,kotlin.Float)` is outside of the range `[0, 1]`, the returned vector will be extrapolated.

| Parameters |
|---|---|
| `start: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the starting vector |
| `end: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the ending vector |
| `ratio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the interpolation ratio |

## Public companion properties

### Down

```
val Down: Vector2
```

Vector with y set to negative one and all other components set to zero.

### Left

```
val Left: Vector2
```

Vector with x set to negative one and all other components set to zero.

### One

```
val One: Vector2
```

Vector with all components set to one.

### Right

```
val Right: Vector2
```

Vector with x set to one and all other components set to zero.

### Up

```
val Up: Vector2
```

Vector with y set to one and all other components set to zero.

### Zero

```
val Zero: Vector2
```

Vector with all components set to zero.

## Public constructors

### Vector2

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
Vector2(other: Vector2)
```

Creates a new vector with the same values as the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#(androidx.xr.runtime.math.Vector2)` vector.

### Vector2

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
Vector2(x: Float = 0.0f, y: Float = 0.0f)
```

## Public functions

### clamp

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

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

Returns a new vector with the values clamped between `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#clamp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)` and `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#clamp(androidx.xr.runtime.math.Vector2,androidx.xr.runtime.math.Vector2)` vectors.

| Parameters |
|---|---|
| `min: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the minimum clamp values |
| `max: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2` | the maximum clamp values |

### copy

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
inline fun copy(x: Float = this.x, y: Float = this.y): Vector2
```

Returns a copy of the vector.

| Parameters |
|---|---|
| `x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = this.x` | the new x value for the copied vector |
| `y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = this.y` | the new y value for the copied vector |

### cross

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
inline infix fun cross(other: Vector2): Float
```

Returns the cross product of this vector and the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#cross(androidx.xr.runtime.math.Vector2)` vector.

### div

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
inline operator fun div(c: Float): Vector2
```

Returns a new vector with this vector divided by a scalar amount.

| Parameters |
|---|---|
| `c: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the scalar to divide by |

### dot

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
inline infix fun dot(other: Vector2): Float
```

Returns the dot product of this vector and the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#dot(androidx.xr.runtime.math.Vector2)` vector.

### equals

```
open operator fun equals(other: Any?): Boolean
```

Returns true if this vector is equal to the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#equals(kotlin.Any)`.

### hashCode

```
open fun hashCode(): Int
```

### inverse

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun inverse(): Vector2
```

Returns the component-wise multiplicative inverse of this vector.

### minus

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
inline operator fun minus(other: Vector2): Vector2
```

Returns a new vector with the difference of this vector and the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#minus(androidx.xr.runtime.math.Vector2)` vector.

### plus

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
operator fun plus(other: Vector2): Vector2
```

Returns a new vector with the sum of this vector and the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#plus(androidx.xr.runtime.math.Vector2)` vector.

### scale

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
inline fun scale(other: Vector2): Vector2
```

Returns a new vector by component-wise multiplying this vector by `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#scale(androidx.xr.runtime.math.Vector2)`.

### times

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
inline operator fun times(c: Float): Vector2
```

Returns a new vector multiplied by a scalar amount.

| Parameters |
|---|---|
| `c: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the scalar to multiply by |

### toNormalized

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun toNormalized(): Vector2
```

Returns a normalized version of this vector. A zero-length vector has no direction to normalize and returns `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector2#Zero()` rather than a vector of NaN components.

### toString

```
open fun toString(): String
```

### unaryMinus

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
inline operator fun unaryMinus(): Vector2
```

Negates the values of this vector.

## Public properties

### length

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val length: Float
```

The length of the vector.

### lengthSquared

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val lengthSquared: Float
```

The squared length of the vector.

### x

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val x: Float
```

the x component of the vector

### y

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val y: Float
```

the y component of the vector