vector2
Math
2 Properties
4 Methods
vector2
The vector2 class represents 2D floating point coordinates (X, Y). It supports arithmetic operator overloading (+, -, *), magnitude calculation, normalization, and dot products.
Overview
Properties (2)
| Property | Type | Summary |
|---|---|---|
x
|
number
|
The X coordinate of the 2D vector. |
y
|
number
|
The Y coordinate of the 2D vector. |
Methods (4)
| Method Signature | Returns | Summary |
|---|---|---|
vector2:dot(other)
|
number
|
Calculates the dot product with another 2D vector. |
vector2:length()
|
number
|
Returns the length (magnitude) of the vector. |
vector2.new(x, y)
|
vector2
|
Constructs a new 2D vector. |
vector2:normalized()
|
vector2
|
Returns a normalized unit vector pointing in the same direction. |
Detailed Reference
vector2.x
The X coordinate of the 2D vector.
Parameters
None
Returns
numberThe X coordinate component.
Description
Reads or writes the X component of the vector.
vector2.y
The Y coordinate of the 2D vector.
Parameters
None
Returns
numberThe Y coordinate component.
Description
Reads or writes the Y component of the vector.
vector2:dot(other)
Calculates the dot product with another 2D vector.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
other | vector2 | The other vector. |
Returns
numberThe scalar dot product.
Description
Returns x1 x2 + y1 y2.
vector2:length()
Returns the length (magnitude) of the vector.
Parameters
None
Returns
numberMagnitude / Euclidean length.
Description
Calculates the Euclidean length sqrt(x^2 + y^2).
vector2.new(x, y)
Constructs a new 2D vector.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x | number | The X coordinate. | |
y | number | The Y coordinate. |
Returns
vector2Newly constructed 2D vector.
Description
Creates a new 2D vector with the specified X and Y coordinates.
local v = vector2.new(10.5, 20.0)vector2:normalized()
Returns a normalized unit vector pointing in the same direction.
Parameters
None
Returns
vector2Unit vector with length 1.0.
Description
Scales the vector to unit length (1.0). Returns (0, 0) if the vector is zero.