Class Vector3

Vector with 3 floating point components: (x, y, z).

Vector3 constructors

Functions which can be used to create new instances of Vector3.

Synopsis

Methods
Vector3()

Default constructor, initializes the vector to (0.0, 0.0, 0.0)

Vector3()

Constructor, initializes the vector to (x, y, z)

Vector3()

Constructor, initializes the vector to (v, v, v)

Vector3()

Default constructor, initializes the vector to (0.0, 0.0, 0.0).

Example
local vector3 = Vector3()
Vector3(x, y, z)

Constructor, initializes the vector to (x, y, z).

Example
local vector3 = Vector3(x, y, z)
Parameters
x (float)

x component of the vector.

y (float)

y component of the vector.

z (float)

z component of the vector.

Vector3(v)

Constructor, initializes the vector to (v, v, v).

Example
local vector3 = Vector3(v)
Parameters
v (float)

x, y and z components of the vector.

Vector3 methods

Methods of Vector3 class.

Synopsis

Methods
Vector3.zero()

Returns the vector with each element being zero

Vector3.one()

Returns the vector with each element being one

Vector3:getX()

Returns the x element of the vector

Vector3:getY()

Returns the y element of the vector

Vector3:getZ()

Returns the z element of the vector

Vector3:setX()

Sets the x element of the vector

Vector3:setY()

Sets the y element of the vector

Vector3:setZ()

Sets the z element of the vector

Vector3:minimumAxis()

Returns axis based on the minimum component of Vector3

Vector3:maximumAxis()

Returns axis based on the largest component of Vector3

Vector3:hasNan()

Returns true if and only if at least one of the vector values is NaN

Vector3:length()

Calculates the length a vectors

Vector3:squaredLength()

Calculates the squared length a vectors

Vector3:normalized()

Normalizes the vector and returns the resulting vector

Vector3.lowestValue()

Returns the vector with each element having the most negative float value

Vector3.highestValue()

Returns the vector with each element having the most positive float value

Vector3.nan()

Returns the vector with each element being NaN

Vector3.positiveInfinity()

Returns the vector with each element being the positive infinity

Vector3.negativeInfinity()

Returns the vector with each element being the negative infinity

Vector3.positiveX()

Returns the unit vector pointing right

Vector3.positiveY()

Returns the unit vector pointing up

Vector3.positiveZ()

Returns the unit vector pointing backward

Vector3.negativeX()

Returns the unit vector pointing left

Vector3.negativeY()

Returns the unit vector pointing down

Vector3.negativeZ()

Returns the unit vector pointing forward

Vector3.zero()

Returns the vector with each element being zero.

Return Values
(Vector3)

Vector with zeroed elements.

Vector3.one()

Returns the vector with each element being one.

Return Values
(Vector3)

Vector with unit element values.

Vector3:getX()

Returns the x element of the vector.

Return Values
(float)

The x element.

Vector3:getY()

Returns the y element of the vector.

Return Values
(float)

The y element.

Vector3:getZ()

Returns the z element of the vector.

Return Values
(float)

The z element.

Vector3:setX(value)

Sets the x element of the vector.

Parameters
value (float)

The new value of the x element.

Vector3:setY(value)

Sets the y element of the vector.

Parameters
value (float)

The new value of the y element.

Vector3:setZ(value)

Sets the z element of the vector.

Parameters
value (float)

The new value of the z element.

Vector3:minimumAxis()

Returns axis based on the minimum component of Vector3.

Return Values
(Vector3)

If X component is smallest, (1, 0, 0), else if Y component is smallest, (0, 1, 0), else (0, 0, 1).

Vector3:maximumAxis()

Returns axis based on the largest component of Vector3.

Return Values
(Vector3)

If X component is largest, (1, 0, 0), else if Y component is largest, (0, 1, 0), else (0, 0, 1).

Vector3:hasNan()

Returns true if and only if at least one of the vector values is NaN.

Vector3:length()

Calculates the length a vectors.

Return Values
(float)

sqrt(xx + yy + z*z)

Vector3:squaredLength()

Calculates the squared length a vectors.

Return Values
(float)

xx + yy + z*z

Vector3:normalized()

Normalizes the vector and returns the resulting vector.

Return Values
(Vector3)

The normalized vector.

Vector3.lowestValue()

Returns the vector with each element having the most negative float value.

Return Values
(Vector3)

Vector with the lowest possible value.

Vector3.highestValue()

Returns the vector with each element having the most positive float value.

Return Values
(Vector3)

Vector with the highest possible value.

Vector3.nan()

Returns the vector with each element being NaN.

Return Values
(Vector3)

Vector with NaN elements.

Vector3.positiveInfinity()

Returns the vector with each element being the positive infinity.

Return Values
(Vector3)

Vector with positive infinity elements.

Vector3.negativeInfinity()

Returns the vector with each element being the negative infinity.

Return Values
(Vector3)

Vector with negative infinity elements.

Vector3.positiveX()

Returns the unit vector pointing right.

Return Values
(Vector3)

Vector3(1.0f, 0.0f, 0.0f).

Vector3.positiveY()

Returns the unit vector pointing up.

Return Values
(Vector3)

Vector3(0.0f, 1.0f, 0.0f).

Vector3.positiveZ()

Returns the unit vector pointing backward.

Return Values
(Vector3)

Vector3(0.0f, 0.0f, 1.0f).

Vector3.negativeX()

Returns the unit vector pointing left.

Return Values
(Vector3)

Vector3(-1.0f, 0.0f, 0.0f).

Vector3.negativeY()

Returns the unit vector pointing down.

Return Values
(Vector3)

Vector3(0.0f, -1.0f, 0.0f).

Vector3.negativeZ()

Returns the unit vector pointing forward.

Return Values
(Vector3)

Vector3(0.0f, 0.0f, -1.0f).

Vector3 functions

Vector3 specific standalone functions, which are not a part of the Vector3 class.

Synopsis

Functions
componentAbs()

Calculates component-wise absolute value for all elements and returns resulting vector

componentCeil()

Calculates component-wise ceil value for all elements and returns resulting vector

componentFloor()

Calculates component-wise floor value for all elements and returns resulting vector

componentRound()

Calculates component-wise rounded value for all elements and returns resulting vector

componentSqrt()

Calculates component-wise square root all elements and returns resulting vector

componentWiseMax()

Calculates the component-wise maximum for all vector elements and returns the resulting vector

componentWiseMin()

Calculates the component-wise minimum for all vector elements and returns the resulting vector

componentWiseMultiply()

Multiplies component-wise all vector elements and returns the resulting vector

componentWiseDivide()

Divides component-wise all vector elements and returns the resulting vector

componentWiseRemainder()

Calculates component-wise the remainder for all vector elements and returns the resulting vector

componentAdd()

Adds a value to all elements of a vector and returns the result

componentSubtract()

Subtracts a value from all elements of a vector and returns the result

componentAllLessThan()

Returns whether each component of the first vector is less than the corresponding component of the second vector

componentAllLessThanOrEqual()

Returns whether each component of the first vector is less than or equal to the corresponding component of the second vector

componentAllGreaterThan()

Returns whether each component of the first vector is greater than the corresponding component of the second vector

componentAllGreaterThanOrEqual()

Returns whether each component of the first vector is greater than or equal to the corresponding component of the second vector

dotProduct()

Calculates the dot product of two vectors

crossProduct()

Calculates the cross product of two vectors

getOrthogonalVector()

Finds a vector that is orthogonal to the given vector

sRGBToLinear()

Converts to whole Vector3 from sRGB to linear

linearTosRGB()

Converts to whole Vector3 from linear to sRGB

hslTosRGBColor()

Converts a Vector3 from HSL color space to sRGB color space

sRGBToHSLColor()

Converts a Vector3 from sRGB color space to HSL color space

componentAbs(v)

Calculates component-wise absolute value for all elements and returns resulting vector.

Parameters
v (Vector3)

Vector input.

Return Values
(Vector3)

The result vector.

componentCeil(v)

Calculates component-wise ceil value for all elements and returns resulting vector.

Parameters
v (Vector3)

Vector input.

Return Values
(Vector3)

The result vector.

componentFloor(v)

Calculates component-wise floor value for all elements and returns resulting vector.

Parameters
v (Vector3)

Vector input.

Return Values
(Vector3)

The result vector.

componentRound(v)

Calculates component-wise rounded value for all elements and returns resulting vector.

Parameters
v (Vector3)

Vector input.

Return Values
(Vector3)

The result vector.

componentSqrt(v)

Calculates component-wise square root all elements and returns resulting vector.

Parameters
v (Vector3)

Vector input.

Return Values
(Vector3)

The result vector.

componentWiseMax(v1, v2)

Calculates the component-wise maximum for all vector elements and returns the resulting vector.

Parameters
v1 (Vector3)

The first vector.

v2 (Vector3)

The second vector.

Return Values
(Vector3)

The result vector.

componentWiseMin(v1, v2)

Calculates the component-wise minimum for all vector elements and returns the resulting vector.

Parameters
v1 (Vector3)

The first vector.

v2 (Vector3)

The second vector.

Return Values
(Vector3)

The result vector.

componentWiseMultiply(v1, v2)

Multiplies component-wise all vector elements and returns the resulting vector.

Parameters
v1 (Vector3)

The first vector.

v2 (Vector3)

The second vector.

Return Values
(Vector3)

The result vector.

componentWiseDivide(v1, v2)

Divides component-wise all vector elements and returns the resulting vector.

Parameters
v1 (Vector3)

The first vector.

v2 (Vector3)

The second vector.

Return Values
(Vector3)

The result vector.

componentWiseRemainder(v1, v2)

Calculates component-wise the remainder for all vector elements and returns the resulting vector.

Parameters
v1 (Vector3)

The first vector.

v2 (Vector3)

The second vector.

Return Values
(Vector3)

The result vector.

componentAdd(v, scalar)

Adds a value to all elements of a vector and returns the result.

Parameters
v (Vector3)

A vector.

scalar (float)

A scalar.

Return Values
(Vector3)

The result vector.

componentSubtract(v, scalar)

Subtracts a value from all elements of a vector and returns the result.

Parameters
v (Vector3)

A vector.

scalar (float)

A scalar.

Return Values
(Vector3)

The result vector.

componentAllLessThan(a, b)

Returns whether each component of the first vector is less than the corresponding component of the second vector.

Parameters
a (Vector3)

First vector.

b (Vector3)

Second vector.

Return Values
(bool)

If each component of the first vector is less than the corresponding component of the second vector, true, otherwise false.

componentAllLessThanOrEqual(a, b)

Returns whether each component of the first vector is less than or equal to the corresponding component of the second vector.

Parameters
a (Vector3)

First vector.

b (Vector3)

Second vector.

Return Values
(bool)

If each component of the first vector is less than or equal to the corresponding component of the second vector, true, otherwise false.

componentAllGreaterThan(a, b)

Returns whether each component of the first vector is greater than the corresponding component of the second vector.

Parameters
a (Vector3)

First vector.

b (Vector3)

Second vector.

Return Values
(bool)

If each component of the first vector is greater than the corresponding component of the second vector, true, otherwise false.

componentAllGreaterThanOrEqual(a, b)

Returns whether each component of the first vector is greater than or equal to the corresponding component of the second vector.

Parameters
a (Vector3)

First vector.

b (Vector3)

Second vector.

Return Values
(bool)

If each component of the first vector is greater than or equal to the corresponding component of the second vector, true, otherwise false.

dotProduct(v1, v2)

Calculates the dot product of two vectors.

Parameters
v1 (Vector3)

The first vector.

v2 (Vector3)

The second vector.

Return Values
(float)

The dot product of the vectors.

crossProduct(v1, v2)

Calculates the cross product of two vectors.

Parameters
v1 (Vector3)

The first vector.

v2 (Vector3)

The second vector.

Return Values
(Vector3)

The cross product of the vectors.

getOrthogonalVector(v)

Finds a vector that is orthogonal to the given vector.

Parameters
v (Vector3)

Source vector. Length must be 1.

Return Values
(Vector3)

Vector orthogonal to the source vector. Not necessarily of unit length.

sRGBToLinear(vec)

Converts to whole Vector3 from sRGB to linear. Since sRGB-to-linear conversion does not take alpha into account, it is possible to interpret Vector3 as just the RGB components.

Parameters
vec (Vector3)

Vector3 representing color in sRGB format.

Return Values
(Vector3)

Vector3 representing color in linear format.

linearTosRGB(vec)

Converts to whole Vector3 from linear to sRGB. Since linear-to-sRGB conversion does not take alpha into account, it is possible to interpret Vector3 as just the RGB components.

Parameters
vec (Vector3)

Vector3 representing color in linear format.

Return Values
(Vector3)

Vector3 representing color in sRGB format.

hslTosRGBColor(vec)

Converts a Vector3 from HSL color space to sRGB color space. Since the conversion does not take the alpha channel into account, it is possible to interpret the returned Vector3 as the red, green, and blue components.

Parameters
vec (Vector3)

Vector3 that represents a color in the HSL color space.

Return Values
(Vector3)

Vector3 that represents the color in the sRGB color space.

sRGBToHSLColor(vec)

Converts a Vector3 from sRGB color space to HSL color space. Since the conversion does not take the alpha channel into account, it is possible to interpret the returned Vector3 as the hue, saturation, and lightness components.

Parameters
vec (Vector3)

Vector3 that represents a color in the sRGB color space.

Return Values
(Vector3)

Vector3 that represents the color in the HSL color space.