Skip to content

tes3vector2⚓︎

A simple pair of floating-point numbers.

Properties⚓︎

x⚓︎

The first value in the vector.

Returns:

  • result (number)

y⚓︎

The second value in the vector.

Returns:

  • result (number)

Methods⚓︎

__tostring⚓︎

Converts the vector to a string with 2 decimal places.

local result = myObject:__tostring()

Returns:

  • result (string)

copy⚓︎

Creates a copy of the vector.

local result = myObject:copy()

Returns:


distance⚓︎

Calculates the distance to another vector in the standard way, i.e., using the Euclidean distance.

local result = myObject:distance(vec)

Parameters:

Returns:

  • result (number)

distanceChebyshev⚓︎

Calculates the distance to another vector, using the Chebyshev metric, which is defined as

math.max(math.abs(v1.x - v2.x), math.abs(v1.y - v2.y))

This is useful for ensuring that the x and y coordinates between two vectors are all (independently) within a certain distance from each other.

Here is a geometric description of the difference between the normal distance and the Chebyshev distance for two tes3vector2s v1 and v2:

  • If v1:distance(v2) <= 1, then v2 is contained in a circle around v1 with radius 1 (i.e. diameter 2).
  • If v1:distanceChebyshev(v2) <= 1, then v2 is contained within a square centered around v1, where the square sides have length 2.
local result = myObject:distanceChebyshev(vec)

Parameters:

Returns:

  • result (number)

distanceManhattan⚓︎

Calculates the distance to another vector, using the Manhattan (i.e. city block) metric. In the two-dimensional case, the Manhattan metric can be thought of as the distance that two taxis will have to travel if they're following a grid system. The formula for the Manhattan distance is

math.abs(v1.x - v2.x) + math.abs(v1.y - v2.y)

This is useful for checking how far you'd actually have to move if you're only allowed to move along one axis at a time.

local result = myObject:distanceManhattan(vec)

Parameters:

Returns:

  • result (number)

length⚓︎

Calculates the length of the vector.

local result = myObject:length()

Returns:

  • result (number)

normalize⚓︎

Normalize the vector in-place, or set its components to zero if normalization is not possible. Returns true if the vector was successfully normalized.

local result = myObject:normalize()

Returns:

  • result (boolean)

normalized⚓︎

Get a normalized copy of the vector.

local result = myObject:normalized()

Returns:


Functions⚓︎

new⚓︎

Creates a new vector. If no parameters are provided, an empty set will be constructed.

local vector = tes3vector2.new(x, y)

Parameters:

  • x (number): Default: 0.
  • y (number): Default: 0.

Returns:


Math Operations⚓︎

Addition (+)⚓︎

Left operand type Right operand type Result type Description
tes3vector2 tes3vector2 tes3vector2 Standard vector addition.

Division (/)⚓︎

Left operand type Right operand type Result type Description
tes3vector2 number tes3vector2 Divides the vector by a scalar.

Multiplication (*)⚓︎

Left operand type Right operand type Result type Description
tes3vector2 tes3vector2 tes3vector2 The per-element multiplication of two vectors.
tes3vector2 number tes3vector2 Multiplies the vector by a scalar.

Subtraction (-)⚓︎

Left operand type Right operand type Result type Description
tes3vector2 tes3vector2 tes3vector2 Standard vector subtraction.