Class Vector2¶
Module: require("engine")
A simple 2D vector class of float type
Constructors¶
List of constructors that will create an instance of Vector2
.
new()¶
Default constructor that initializes the vector to [0, 0]
new(x, y)¶
Parametrized constructor that initializes the vector to [x, y]
Parameters:
x:
number
- The x componenty:
number
- The y component
Member Functions¶
List of member functions within the table Vector2
.
These functions need to be called using the colon symbol on some instance of Vector2
.
distance(other)¶
Calculates a distance to some other vector
Parameters:
other:
Vector2
- The other vector to get distance to
Returns: number
- The distance
rotate(angle)¶
Returns a new vector that is rotated by some angle
Parameters:
angle:
number
- in radians
Returns: Vector2
- A new rotated vector
Example:
local PI = 3.141592653589
local a = engine.Vector2.new(1.0, 0.0)
local b = a:rotate(PI)
-- Prints: Rotated vector [1, 0] by 180 degrees is: [-1, -8.742278e-08]
print(string.format("Rotated vector %s by 180 degrees is: %s", a, b))
Fields¶
List of fields within the table Vector2
.
These variables belong to this class and can be accessed only via an instance of this class.
x¶
Type: number
y¶
Type: number