# Geometric functions¶

Class constructors can be called like this local c = ColorI(255,255,255,255)

## class ColorI¶

class ColorI

Creates a color object with four integer values ( r, g, b, a)

ColorI ColorI(int R, int G, int B, int A)

Parameters:

• int R: The red Channel of the color (Values: 0-255)
• int G: The green Channel of the color (Values: 0-255)
• int B: The blue Channel of the color (Values: 0-255)
• int A: The alpha Channel of the color (Values: 0-255)
Returns: ColorI

Example: This example creates two new ColorI objects and then displays them in the console

local color1 = ColorI(255,255,255,255) -- White
local color2 = ColorI(0,0,0,255) --Black
print(tostring(color1)) --Writes color1 as string to the console
print(tostring(color2)) --Writes color2 as string to the console

bool __eq(ColorI color)

compare two ColorI to check if they are equal Parameters

• ColorI color: The color to compare with
Returns: boolean

Example: This example creates two colors and compares them.

local white = ColorI(255,255,255,255) -- White Color
local black = ColorI(0,0,0,0) --Black Color
if (white:__eq(black)) then -- if white is equal to black
print("Yes, it's the same")
else
print("No, they are different")
end

char __tostring()

Converts color to string

Returns: LUA string in this format %i, %i, %i, %i

Example: This Example creates a new Color and converts it to a string

local color = ColorI(255,255,255,255)
print(color:__tostring()) -- 255, 255, 255, 255


## class ColorF¶

class ColorF
Color with 4 float Values for RGBA
ColorF ColorF(float R, float G, float B, float A)

Parameters:

• float R: The red Channel of the color (Values: 0-1)
• float G: The green Channel of the color (Values: 0-1)
• float B: The blue Channel of the color (Values: 0-1)
• float A: The alpha Channel of the color (Values: 0-1)
Returns: ColorF

Example: This example creates three new ColorF objects and then displays them in the console

local color1 = ColorF(1,1,1,1); --White created
local color2 = ColorF(0,0,0,1); --Black created
local color3 = ColorF(0.12,0.12,0.12,1); --Grey created
print(tostring(color1)) --Writes color1 as string to the console
print(tostring(color2)) --Writes color2 as string to the console
print(tostring(color3.r)) --Writes only the red Value of color3 in the Console

char __tostring()

Converts color to string

Returns: LUA string in this format %g, %g, %g, %g
local color = ColorF(0.1,0.1,0.1,1)
print(color:__tostring()) -- 0.1, 0.1, 0.1, 0.1

ColorLinear4F asLinear4F()
Returns: ColorLinear4F

Example: This example creates a color object and converts it to a ColorLinear4F

local color = ColorF(0.1,0.1,0.1,0.1)
local vector = color:asLinear4F()
print(tostring(vector))

setFromString(char *str)

parse a string and set the colors.

Parameters:

• char str: The Color-String, that should be converted (A list can be found here)

Warning

This doesn’t create an object, you need to have an already initialised variable and them parse the text with this function

Example: Defines a new color and then sets it to black.

local color = ColorF(255, 255, 255, 255)
color:setFromString("Black")
print(color:__tostring())


## class Point2F¶

class Point2F
Point2F Point2F(float x, float y)

Creates a new 2D-Point with 2 Floats

Parameters:

• float x: the x-Value of the Point
• float y: the y-Value of the Point

Example:

local point = Point2F(12.56, 20.64)
print(point.x) -- prints 12.56
print(point.y) -- prints 20.64

char __tostring()

Creates a string that contains the x and y variables.

Returns: LUA string in this format %g, %g

Example:

local point = Point2F(12.56, 20.64);
print(point:__tostring());


## class Point3F¶

class Point3F
Point3F Point3F(float x, float y, float z)

Parameters:

• float x: the x-Value of the Point
• float y: the y-Value of the Point
• float z: the z-Value of the Point
Returns: Point3F

Example:

local point = Point2F(12.56, 20.64, 30.12)
print(point.x) -- prints 12.56
print(point.z) -- prints 30.12
print(tostring(point))--Prints the Point as a string

float len()

Returns the length of a point where the root is drawn from all 3 parts.

Returns: (number) vector length calculated using: sqrt(x*x + y*y + z*z)

Example: This example creates a Point and prints the length of the Point

local point = Point2F(12.56, 20.64, 30.12)
print(point:len()) --prints 38.61

neg()

This function Inverts the vector

Example: This example creates a Point and prints inversation the of the Point into the console

local point = Point3F(12.56, 20.64, 30.12) --Creates a new Point
point:neg() --Inverts the Vector
print(tostring(point)) --prints -12.56, -20.64, -30.12


Warning

It does not create an object but reverses it in this object.

float lenSquared()

Returns the squared length of the vector.

Example: This example creates a Point and prints the squared

local point = Point3F(12.56, 20.64, 30.12) --Creates a new Point
local length = point:lenSquared() --
print(length) -- prints: 1490.97

Point2F asPoint2F()

Converts the Point3F to a Point2F by leaving out the z field.

Returns: Point2F with the same x and y
local point3 = Point3F(12.56, 20.64, 30.12) --Creates a new Point
local point2 = point3:asPoint2F()
print(tostring(point2)) --prints 12.56, 20.64

set(float x, float y, float z)

Sets all arguments in a single call

Parameters:

• float x: the new x-Value of the Point
• float y: the new y-Value of the Point
• float z: the new z-Value of the Point
local point = Point3F(12.56, 20.64, 30.12) -- Creates a new Point
point:set(18.65, 155.3, 245.11)
print(tostring(point)) -- Prints 18.65, 155.3, 245.11 in the console

setAll(float xyz)

Sets all arguments to the same value

Parameters:

-float xyz: The new Value of all members

Example: This example creates a new Point3F and sets all his member to the same.

local point = Point3F(12.56, 20.64, 30.12)
point:setAll(500.1) --Set all Values to 500.1
print(tostring(point)) --prints 500.1, 500.1, 500.1

zero()

Sets the vector to 0.

Exampple: This example creates a new Point3F and sets all his member to 0

local point = Point3F(12.56, 20.64, 30.12)
point:zero() --Set all Values to 0
print(tostring(point)) --prints 0,0,0

normalize()

This function returns the normalized values of a vector.

Example: This example creates a new Point3F and normalize it.

local point = Point3F(12.56, 20.64, 30.12)
point:normalize() --normalize the Point
print(tostring(point)) --prints 0.325278, 0.534533, 0.780045

normalizeSafe()

Normalizes the vector.

local point = Point3F(12.56, 20.64, 30.12)
point:normalizeSafe() --normalize the Point
print(tostring(point)) --prints 0.325278, 0.534533, 0.780045

Point3F __add(Point3F point)

Parameters:

• Point3F point: The Point3F with which you want to sum up.

Example See: Point3F::__div()

Point3F __sub(Point3F point)

Parameters:

• Point3F point: The Point3F with which you want to subtract.

Subtraction of two Point3F-Objects

Example See: Point3F::__div()

Point3F __unm(Point3F point)

Parameters:

• Point3F point: The Point3F with which you want to unary minus.

Unary minus of two Point3F-Objects

Example See: Point3F::__div()

Point3F __mul(Point3F point)

Multiplication of two Point3F-Objects

Parameters:

• Point3F point: The Point3F with which you want to multiply.

Example See: Point3F::__div()

Point3F __div(Point3F point)

Division of two Point3F-Objects

Parameters:

• Point3F point: The Point3F to divide by

Example for all Math-Functions of Point3F:

local point1 = Point3F(12.56, 20.64, 30.12)
local point2 = Point3F(12.34, 56.78, 90.12)
print(tostring(point1:__add(point2))) -- prints 24.9, 77.42, 120.24
--Subtraction:
print(tostring(point1:__sub(point2))) -- prints 0.22, -36.14, -60
--Unary minus:
print(tostring(point1:__unm(point2))) -- prints -12.56, -20.64, -30.12
--Multiplication:
print(tostring(point1:__mul(point2))) -- prints 154.99, 1171.94, 2714.41
--Division:
print(tostring(point1:__div(point2))) -- prints 1.01783, 0.363508, 0.334221

Point3F __eq(Point3F)

Checks the equality of two Point3F

Returns: (bool) isEqual

Example: Creates two Point3F-Objects and compares them

local point1 = Point3F(12.56, 20.64, 30.12)
local point2 = Point3F(12.34, 56.78, 90.12)
if (point1.__eq(point2)) then --If point1 is equal point2
print("equal")
else
print("not equal")
end

string __tostring()

Converts Point3F to String

Returns: a LUA string in this format %g, %g, %g

Example: Creates a Point and converts this to a string

local point1 = Point3F(12.56, 20.64, 30.12)
print(point1:__tostring()) -- prints 12.56, 20.64, 30.12


## class Point4F¶

class Point4F

A 4-Dimensional point with Floats

Point4F Point4F(float x, float y, float z, float w)

Parameters:

• float x: x-Value of the Point
• float y: y-Value of the Point
• float z: z-Value of the Point
• float w: w-Value of the Point
Returns: Point4F

Example: This example creates a new Point4F and prints this in the console

local point = Point4F(12.3, 45.6, 78.9, 10.1)     -- Creates a new Point4F
print(point:__tostring()) -- prints 12.3, 45.6, 78.9, 10.1
print(point.w) --prints 10.1 in the console

string __tostring()

New in version 0.11.

Returns: a LUA string in this format %g, %g, %g, %g

Example: See: Point4F

## class QuatF¶

class QuatF
QuatF QuatF(float x, float y, float z, float w)

Parameters:

• float x: x-Value of the Point
• float y: y-Value of the Point
• float z: z-Value of the Point
• float w: w-Value of the Point
Returns: QuatF
local q_point = QuatF(12.3, 45.6, 78.9, 10.1)     -- Creates a new QuatF
print(q_point:__tostring()) -- prints 12.3, 45.6, 78.9, 10.1
print(q_point.w) --prints 10.1 in the console

__mul(QuatF b)

Parameters:

• QuatF b: The QuatF-object that is multiplied by the element.

Example: This example creates a QuatF-Element and multiply it with another.

local q_point = QuatF(12.3, 45.6, 78.9, 10.1)       -- Creates a new QuatF
local q_point2 = QuatF(98.7, 65.4, 32.1, 90.8)      -- Creates another QuatF
local result = q_point:__mul(q_point2) -- multiply q_point1 with q_point2
print(result:__tostring()) -- prints 12.3, 45.6, 78.9, 10.1

string __tostring()

New in version 0.11.

transforms a QuatF to a string

Returns: a LUA string in this format %g, %g, %g, %g

Example: See: QuatF

## class MatrixF¶

class MatrixF

Class to create a 4x4 Matrix float (32bit)

MatrixF(bool identity = false)

Parameters:

• bool identity: identity Matrix enabled

Info: In mathematics, an identity matrix is a square matrix whose main diagonal elements are one and whose extra-diagonal elements are zero.

Example: This example creates a MatrixF and outputs this on the console

local matrix = MatrixF()
print(matrix:__tostring()) --Returns row 1: 0,0,0,0; row 2: 0,0,0,0; row 3: 0,0,0,0

setColumn(int col, Point3F p)

Set the specified column from a Point3F.

Parameters:

• int col: The column
• Point3F p: The Point3F that should be included

The bottom-most row is not set.

local matrix = MatrixF(true) -- Creates a new Matrix
local point1 = Point3F(522,452,125) -- creation of the first Point
local point2 = Point3F(456,123,879) -- creation of the second Point
matrix:setColumn(0, point1) -- Sets the first column to Point1
matrix:setColumn(1, point2) -- Sets the second column to Point2
print(tostring(matrix)) -- Prints the things below in the console
-- 522, 456, 0, 0
-- 452, 123, 0, 0
-- 125, 879, 1, 0

Point3F getColumn(S32 colId)

Copy the requested column into a Point3F.

Parameters:

• int colId: The column-number
Returns: Point3F

Example: creates a matrix, puts two Point3F in it and prints their input by getColumn

local matrix = MatrixF(true)
local point1 = Point3F(522,452,125)
local point2 = Point3F(456,123,879)
matrix:setColumn(0, point1)
matrix:setColumn(1, point2)
print(tostring(matrix:getColumn(2))) -- Prints: 522, 452, 125
print(tostring(matrix:getColumn(1))) -- Prints: 123, 456, 789

scale(Point3F scale)

Set the scale of a matrix

Parameters:

• Point3F scale: Scale to set on each axis

Example: This Example creates a new Matrix and 2 points, that are inserted

local matrix = MatrixF(false)
local point1 = Point3F(4,5,9)
local point2 = Point3F(1,2,3)
matrix:setColumn(0, point1)
matrix:setColumn(1, point2)
local point3 = Point3F(6,7,8)
matrix:scale(point3)
print(tostring(matrix)) -- prints -> look below
-- 24, 7, 0, 0
-- 30, 14, 0, 0
-- 54, 21, 0, 0

MatrixF inverse()

New in version 0.11.

inverse the matrix

Returns: the invert transformation matrix

Example: Creates a matrix, two Point3F and includes them into the matrix, inverts the matrix and outputs it as a string.

local matrix = MatrixF(false)
local point1 = Point3F(4.0,5.0,9.0)
local point2 = Point3F(1.0,2.0,3.0)
matrix:setColumn(0, point1)
matrix:setColumn(1, point2)
matrix:inverse()
print(tostring(matrix))

mulP4F(Point4F p)

New in version 0.11.

Multiply the matrix to the point, The result is stored in p

string __tostring()

New in version 0.11.

Converts the Matrix to a LUA-String

Returns: a LUA string in this format

%g, %g, %g, %g

%g, %g, %g, %g

%g, %g, %g, %g

Example: See: MatrixF

## class Box3F¶

class Box3F
Box3F Box3F()

New in version 0.12.

Creates a new Box3F-Object.

Returns: Invalid Box3F

Example: This Example creates a new Box3F-Object

local box = Box3F()

Point3F getCenter()

Gets the Center Point of the bounding Box

Returns: the center point of the bounding box.

Example: This Example creates a new Box3F and prints its Center to the console

local box = Box3F(3, 4)
local center = box:getCenter()
print(tostring(center)) -- prints 0,0,0

setCenter(Point3F center)

Set the center of the box

Parameters:

• Point3F center: The new Center Point of The Box3F

Example: Creates a new Box3F, sets its center point and prints it to the console

local box = Box3F(3, 4)
local point = Point3F(4.0, 5.0, 6.0)
box:setCenter(point)
local center = box:getCenter()
print(tostring(center)) -- prints 0,0,0

Point3F getExtents()

Gets the Extents of the Box3F-Object

Returns: Point3F the extends of the bounding box.

Example: See: MatrixF

setExtents(Point3F size)

Set the extends of the box

Parameters:

• Point3F size: the new Extents of the Box3F

Example: This Example creates a new Box3F and defines its

local box = Box3F()
box:setExtents(Point3F(12.0,12.0,12.0))
local extends = box:getExtents()
print(tostring(extends)) -- prints 12, 12, 12


## class OrientedBox3F¶

class OrientedBox3F
• usefull?
• need to find example first to continue
Point3F getCenter()
Returns: the center point of the bounding box.
Point3F getAxis(int axis)
Parameters: axis – axis the normalized axis vector for the given world-space axis.
Point3F getHalfExtents()
Warning: Broken : It returns full extents (same as scale) the half-extents along each axis.

Since the OBBs are symmetrical across each axis, we store half-extents instead of full extents as usually half-extents are needed in the computations.

Point3F getPoint(i)
Returns: the corner points of the box.
bool isContained(Point3F)
Returns: true if the given point is contained in the OBB.