createVector();
Create a vector instance.
createVector(x, y);
Arguments
x
The first component of the vectory
The second component of the vectorlocal point = createVector(80, 125);
print(point);
createVector(x, y, z);
Arguments
x
The first component of the vectory
The second component of the vectorz
The third component of the vectorlocal point = createVector(130, 200, 60);
print(point);
Returns
Vector
The created vectorVector.print();
Since a Vector
implements a print
method, it can be used in the print
function.
local a = createVector(3, 5);
-- With print
print(a);
-- With class method
Vector.print(a);
-- with instance
a:print();
Vector.dist(a, b);
No description
Arguments
a
The first pointb
The second pointReturns
number
The distance between the two pointslocal a = createVector(300, 500);
local b = createVector(200, 250);
local distance = a:dist(b);
print(distance);
Vector.dot(a, b);
No description
Arguments
a
The first vectorb
The second vectorReturns
number
The dot productlocal a = createVector(3, 5);
local b = createVector(1, 3);
-- From prototype
print(a:dot(b)); -- 18.0
-- With static method
print(Vector.dot(a, b)); -- 18.0
-- With concat syntax
print(a .. b); -- 18.0
Vector.add(a, b);
No description
Arguments
a
The first vectorb
The second vectorReturns
Vector
The added vectorlocal a = createVector(4, 2);
local b = createVector(2, 1);
-- Non-mutable
print(Vector.add(a, b)); -- { 6.0, 3.0 }
print(a + b); -- { 6.0, 3.0 }
print(a); -- { 4.0, 2.0 }
-- Mutable
print(a:add(b)); -- { 6.0, 3.0 }
print(a) -- { 6.0, 3.0 }
Vector.sub(a, b);
No description
Arguments
a
The first vectorb
The second vectorReturns
Vector
The subtracted vectorlocal a = createVector(3, 5);
local b = createVector(2, 3);
-- Non-mutable
print(Vector.sub(a, b)); -- { 1.0, 2.0 }
print(a - b); -- { 1.0, 2.0 }
print(a); -- { 3.0, 5.0 }
-- Mutable
print(a:sub(b)); -- { 1.0, 2.0 }
print(a); -- { 1.0, 2.0 }
Vector.mult(a, b);
No description
Arguments
a
The first vectorb
The second vectorReturns
Vector
The multiplied vectorlocal a = createVector(3, 5);
local b = createVector(2, 3);
-- Non-mutable
print(Vector.mult(a, b)); -- { 6.0, 15.0 }
print(a * b); -- { 6.0, 15.0 }
print(a); -- { 3.0, 5.0 }
-- Mutable
print(a:mult(b)); -- { 3.0, 15.0 }
print(a); -- { 3.0, 15.0 }
Vector.div(a, b);
No description
Arguments
a
The first vectorb
The second vectorReturns
Vector
The divided vectorlocal a = createVector(4, 2);
local b = createVector(2, 1);
-- Non-mutable
print(Vector.div(a, b)); -- { 2.0, 2.0 }
print(a / b); -- { 2.0, 2.0 }
print(a); -- { 4.0, 2.0 }
-- Mutable
print(a:div(b)); -- { 2.0, 2.0 }
print(a) -- { 2.0, 2.0 }
Vector.idiv(a, b);
No description
Arguments
a
The first vectorb
The second vectorReturns
Vector
The divided vectorlocal a = createVector(7, 8);
local b = createVector(2, 3);
-- Non-mutable
print(Vector.idiv(a, b)) -- { 3.0, 2.0 }
print(a // b); -- { 3.0, 2.0 }
print(a); -- { 7.0, 8.0 }
-- Mutable
print(a:idiv(b)); -- { 3.0, 2.0 }
print(a) -- { 3.0, 2.0 }
Vector.copy();
No description
Returns
Vector
The copied vectorlocal a = createVector(300, 450, 400);
local copy_1 = a:copy();
local copy_2 = Vector.copy(a);
Vector();
No description
Returns
Vector
The composed vectorlocal a = createVector(300, 450, 400);
local copy = a.xyz;
local a_2d = a.xy; -- { 300, 450 }
local b = a.xyx; -- { 300, 450, 300 }
local c = a.zxy; -- { 400, 300, 450 }