vector

v0.1.6
createVector(x, y);

Create a vector instance

Arguments

xThe first component of the vector
yThe second component of the vector

Returns

VectorThe created vector

local point = createVector(80, 125);

print(point);
See createVector in lu5_vector.h
Vector.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();
See Vector.print in lu5_vector.h
Vector.dist(a, b);

No description

Arguments

aThe first point
bThe second point

Returns

numberThe distance between the two points

local a = createVector(300, 500);
local b = createVector(200, 250);

local distance = a:dist(b);
print(distance);
See Vector.dist in lu5_vector.h
Vector.dot(a, b);

No description

Arguments

aThe first vector
bThe second vector

Returns

numberThe dot product

local 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
See Vector.dot in lu5_vector.h
Vector.add(a, b);

No description

Arguments

aThe first vector
bThe second vector

Returns

VectorThe added vector

local 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 }
See Vector.add in lu5_vector.h
Vector.sub(a, b);

No description

Arguments

aThe first vector
bThe second vector

Returns

VectorThe subtracted vector

local 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 }
See Vector.sub in lu5_vector.h
Vector.mult(a, b);

No description

Arguments

aThe first vector
bThe second vector

Returns

VectorThe multiplied vector

local 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 }
See Vector.mult in lu5_vector.h
Vector.div(a, b);

No description

Arguments

aThe first vector
bThe second vector

Returns

VectorThe divided vector

local 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 }
See Vector.div in lu5_vector.h
Vector.idiv(a, b);

No description

Arguments

aThe first vector
bThe second vector

Returns

VectorThe divided vector

local 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 }
See Vector.idiv in lu5_vector.h
Vector.copy();

No description

Returns

VectorThe copied vector

local a = createVector(300, 450, 400);

local copy_1 = a:copy();

local copy_2 = Vector.copy(a);
See Vector.copy in lu5_vector.h
Vector();

No description

Returns

VectorThe composed vector

local 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 }
See Vector in lu5_vector.h