Zum Hauptinhalt springen
Version: latest - a1.172.0 โš–๏ธ

๐Ÿ“ 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
NameTypeBeschreibung
X?floatX Coordinate Default 0
Y?floatY Coordinate Default X

๐Ÿงฝ Propertiesโ€‹

TypeNameBeschreibung
floatXX Coordinate
floatYY Coordinate

๐Ÿฆ  Functionsโ€‹

info

This structure supports +, -, *, /, ==, unary - (negation) and tostring operations.

Distance: floatDistance between two points
DistanceSquared: floatSquared distance between two points
IsNear: booleanEfficiently checks whether vector is near to another vector within a specified radius
Size: floatGet the length (magnitude) of this vector
SizeSquared: floatGet the squared length of this vector
Dot: floatDot product of two vectors
Cross: floatCross product of two vectors
Lerp: Vector2DLinearly interpolates between this vector and another vector

DistanceOptimalโ€‹

Distance between two points

Returns the distance of 2 vectors

local ret = my_vector2d:Distance(other)
Parameters
NameTypeBeschreibung
otherVector2DThe vector to get the distance to
Returns
TypeBeschreibung
floatThe distance between the vectors

DistanceSquaredOptimalโ€‹

Squared distance between two points

Return the squared distance of 2 vectors

local ret = my_vector2d:DistanceSquared(other)
Parameters
NameTypeBeschreibung
otherVector2DThe vector to get the squared distance to
Returns
TypeBeschreibung
floatThe squared distance between the vectors

IsNearOptimalโ€‹

Efficiently checks whether vector is near to another vector within a specified radius

local ret = my_vector2d:IsNear(other, radius)
Parameters
NameTypeBeschreibung
otherVector2DThe vector to compare to
radiusfloatThe radius to check
Returns
TypeBeschreibung
booleanIf the vector is near to the other vector

SizeOptimalโ€‹

Get the length (magnitude) of this vector

local ret = my_vector2d:Size()
Returns
TypeBeschreibung
floatThe length of the vector

SizeSquaredOptimalโ€‹

Get the squared length of this vector

local ret = my_vector2d:SizeSquared()
Returns
TypeBeschreibung
floatThe squared length of the vector

DotOptimalโ€‹

Dot product of two vectors

Returns the dot product between this vector and another vector

local ret = my_vector2d:Dot(other)
Parameters
NameTypeBeschreibung
otherVector2DThe vector to dot with
Returns
TypeBeschreibung
floatthe dot product

CrossOptimalโ€‹

Cross product of two vectors

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
NameTypeBeschreibung
otherVector2DThe vector to cross with
Returns
TypeBeschreibung
floatthe cross product

LerpOptimalโ€‹

Linearly interpolates between this vector and another vector

Returns the linear interpolation between this vector and another vector by the given alpha

local ret = my_vector2d:Lerp(other, alpha)
Parameters
NameTypeBeschreibung
otherVector2DThe vector to interpolate to
alphafloatThe interpolation alpha, where 0 returns this vector and 1 returns the other vector
Returns
TypeBeschreibung
Vector2Dthe interpolated vector