Passer au contenu principal
Version: bleeding-edge 🩸

📏 Vector2D

A Vector2D composed of components (X, Y) with floating point precision. Used mainly for HUD and Drawing on screen.


🎒 Examples

local new_vector = Vector2D(1452.5, 512)

🛠 Constructors

Default Constructor

No description provided

local my_vector2d = Vector2D(X?, Y?)

Parameters

TypeNameDefaultDescription
numberX0X Coordinate
numberYXY Coordinate

🧽 Properties

TypeNameDescription
numberXX Coordinate
numberYY Coordinate

🦠 Functions

info

This structure supports +, -, *, /, == and tostring operations.

ReturnsNameDescription
numberDistanceDistance between two points
numberDistanceSquaredSquared distance between two points
booleanIsNearEfficiently checks whether vector is near to another vector within a specified radius
numberSizeGet the length (magnitude) of this vector
numberSizeSquaredGet the squared length of this vector
numberDotDot product of two vectors
numberCrossCross product of two vectors
Vector2DLerpLinearly interpolates between this vector and another vector

Distance

Returns the distance of 2 vectors
local ret = my_vector2d:Distance(other)

Parameters

TypeParameterDefaultDescription
Vector2Dother Required parameter The vector to get the distance to

Returns

TypeDescription
numberThe distance between the vectors

DistanceSquared

Return the squared distance of 2 vectors
local ret = my_vector2d:DistanceSquared(other)

Parameters

TypeParameterDefaultDescription
Vector2Dother Required parameter The vector to get the squared distance to

Returns

TypeDescription
numberThe squared distance between the vectors

IsNear

Efficiently checks whether vector is near to another vector within a specified radius
local ret = my_vector2d:IsNear(other, radius)

Parameters

TypeParameterDefaultDescription
Vector2Dother Required parameter The vector to compare to
numberradius Required parameter The radius to check

Returns

TypeDescription
booleanIf the vector is near to the other vector

Size

Get the length (magnitude) of this vector
local ret = my_vector2d:Size()

Returns

TypeDescription
numberThe length of the vector

SizeSquared

Get the squared length of this vector
local ret = my_vector2d:SizeSquared()

Returns

TypeDescription
numberThe squared length of the vector

Dot

Returns the dot product between this vector and another vector
local ret = my_vector2d:Dot(other)

Parameters

TypeParameterDefaultDescription
Vector2Dother Required parameter The vector to dot with

Returns

TypeDescription
numberthe dot product

Cross

Returns the cross product between this vector and another vector, which for 2D vectors is a scalar value
local ret = my_vector2d:Cross(other)

Parameters

TypeParameterDefaultDescription
Vector2Dother Required parameter The vector to cross with

Returns

TypeDescription
numberthe cross product

Lerp

Returns the linear interpolation between this vector and another vector by the given alpha
local ret = my_vector2d:Lerp(other, alpha)

Parameters

TypeParameterDefaultDescription
Vector2Dother Required parameter The vector to interpolate to
numberalpha Required parameter The interpolation alpha, where 0 returns this vector and 1 returns the other vector

Returns

TypeDescription
Vector2Dthe interpolated vector