---
title: "Vec2"
description: "API documentation for Vec2"
url: https://developer.disguise.one/python-api/docs/vec2/
---

# Vec2

A two-dimensional vector with x and y components.

See also: [Utility Guide](/plugins/guides/utility)

Base class: _\_BlipValue_

## Properties

#### **maxComponent** : _float_ _(Read-Only)_

Maximum component of the vector.

#### **minComponent** : _float_ _(Read-Only)_

The minimum component of the vector.

#### **x** : _float_

The x component of the vector.

_UserName: X_

#### **y** : _float_

The y component of the vector.

_UserName: Y_

## Constructors

#### **\_\_init\_\_**(self)

#### **\_\_init\_\_**(self, other: _[Vec2](/python-api/docs/vec2#vec2)_)

Copy constructor for Vec2

#### **\_\_init\_\_**(self, v: _[Int2](/python-api/docs/int2#int2)_)

#### **\_\_init\_\_**(self, v: _[Vec](/python-api/docs/vec#vec)_)

#### **\_\_init\_\_**(self, \_x: _float_, \_y: _float_)

## Methods

#### **\_initParams**(self) -> _Any_

A serialisable tuple of the Int2 parameters

#### **abs**(self) -> _[Vec2](/python-api/docs/vec2#vec2)_

The absolute value of the vector.

**Returns** A new vector containing the component-wise absolute value of this vector.

#### **angle**(self) -> _float_

The angle of the vector, measured counter-clockwise from the positive x-axis.

**Returns** The angle of the vector in normalised coordinates.

#### **anyLargerThan**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _bool_

Checks whether any component of this vector is larger than the corresponding component of another vector.

**Parameters**:

-   v: The other vector to compare with.

**Returns** True if any component of this vector is larger than the corresponding component of the other vector.

#### **anySmallerThan**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _bool_

Checks if any component of this vector is smaller than the corresponding component of another vector.

**Parameters**:

-   v: The other vector to compare with.

**Returns** True if any component of this vector is smaller than the corresponding component of the other vector.

#### **aspect**(self) -> _float_

The aspect ratio of the vector, defined as the ratio of the x component to the y component.

**Returns** The aspect ratio of the vector.

#### **dot**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _float_

The dot product of two vectors.

**Parameters**:

-   v: The other vector to calculate the dot product with.

**Returns** The dot product of this vector and the other vector.

#### **length**(self) -> _float_

The length of the vector in 2D space.

**Returns** The length of the vector.

#### **normalise**(self) -> _[Vec2](/python-api/docs/vec2#vec2)_

Normalises the vector to have a length of 1.

**Returns** The normalised vector.

#### **restrict**(self, min: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_, max: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _[Vec2](/python-api/docs/vec2#vec2)_

Restricts the vector to be within a minimum and maximum range.

**Parameters**:

-   min: A vector of minimum values for each component.
-   max: A vector of maximum values for each component.

**Returns** A new vector with components restricted to the minimum and maximum range.

#### **rotate**(self, a: _float_) -> _[Vec2](/python-api/docs/vec2#vec2)_

Rotates the vector by a degrees anticlockwise.

**Parameters**:

-   a: The angle of rotation in degrees.

**Returns** A new vector rotated by the specified angle.

#### **roundClosest**(self, f: _float_) -> _[Vec2](/python-api/docs/vec2#vec2)_

Rounds the components of this vector to the nearest integer multiple of a given factor.

Rounds to the nearest multiple of `f` using the round half toward zero rule  
eg. 0 <= x <= 0.5 will round to 0, 0.5 < x <= 1 will round to 1

**Parameters**:

-   f: The factor to round to.

**Returns** A new vector with rounded components.

#### **roundDown**(self, f: _float_) -> _[Vec2](/python-api/docs/vec2#vec2)_

Rounds the components of this vector down to the nearest integer multiple of a given factor.

**Parameters**:

-   f: The factor to round down to.

**Returns** A new vector with rounded components.

#### **vmax**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _[Vec2](/python-api/docs/vec2#vec2)_

Component-wise maximum of two vectors.

**Parameters**:

-   v: The other vector to compare with.

**Returns** A new vector containing the component-wise maximum of this and the other vector.

#### **vmin**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _[Vec2](/python-api/docs/vec2#vec2)_

Component-wise minimum of two vectors.

**Parameters**:

-   v: The other vector to compare with.

**Returns** A new vector containing the component-wise minimum of this and the other vector.

## Special Methods

#### **\_\_add\_\_**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _[Vec2](/python-api/docs/vec2#vec2)_

Adds two vectors.

**Parameters**:

-   v: The Vec2 object to add to this one.

**Returns** The component-wise sum of this and the input vector.

#### **\_\_div\_\_**(self, s) -> _Any_

Divides the vector by a scalar value.

**Parameters**:

-   s: The scalar value to divide the vector by.

**Returns** A new vector that is the result of dividing the components of this vector by the given scalar value.

#### **\_\_eq\_\_**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _bool_

Tests for equality between two vectors.

**Parameters**:

-   v: The vector to compare with.

**Returns** True if both components of the vectors are equal, false otherwise.

#### **\_\_getitem\_\_**(self, key) -> _Any_

Get an item from the Vec2 by index.

**Parameters**:

-   key: The index of the desired item. Must be 0 or 1

**Returns** The x element if the index is 0, the y element if the index is 1

#### **\_\_len\_\_**(self) -> _Any_

The length of the Vec2

**Returns** Always returns 2

#### **\_\_mul\_\_**(self, s) -> _Any_

Multiplies the vector by a scalar value.

**Parameters**:

-   s: The scalar value to multiply with.

**Returns** A new vector that is the result of multiplying the components of this vector by the given scalar value.

#### **\_\_ne\_\_**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _bool_

Tests for inequality between two vectors.

**Parameters**:

-   v: The other vector to compare with.

**Returns** True if either of the components of the vectors are not equal, false otherwise.

#### **\_\_neg\_\_**(self) -> _Any_

The negative of the Vec2

**Returns** The Vec2 with its x and y components negated

#### **\_\_rdiv\_\_**(self, other) -> _Any_

Divide another vector by this vector

**Parameters**:

-   other: The vector which is divided by this

**Returns** The element-wise division other/self

#### **\_\_repr\_\_**(self) -> _Any_

String representation of the Vec2

#### **\_\_rmul\_\_**(self, s) -> _Any_

Multiplies the vector by a scalar value.

**Parameters**:

-   s: The scalar value to multiply with.

**Returns** A new vector that is the result of multiplying the components of this vector by the given scalar value.

#### **\_\_rtruediv\_\_**(self, other) -> _Any_

Divide another vector by this vector

**Parameters**:

-   other: The vector which is divided by this

**Returns** The element-wise division other/self

#### **\_\_str\_\_**(self) -> _Any_

String representation of the Vec2

#### **\_\_sub\_\_**(self, v: _[Vec2](/python-api/docs/vec2#vec2) | [Int2](/python-api/docs/int2#int2) | [Vec](/python-api/docs/vec#vec)_) -> _[Vec2](/python-api/docs/vec2#vec2)_

Subtracts another vector from this vector.

**Parameters**:

-   v: The Vec2 object to subtract from this vector.

**Returns** The resulting vector after component-wise subtraction.

#### **\_\_truediv\_\_**(self, s) -> _Any_

Divides the vector by a scalar value.

**Parameters**:

-   s: The scalar value to divide the vector by.

**Returns** A new vector that is the result of dividing the components of this vector by the given scalar value.
