Vector3

Reference

class Vector3
module:
x: number
y: number
z: number
static fromData(data)

Create a vector object from data

Parameters:

data (table) – the data table

Returns:

the new Transform object

Return type:

Vector3

static new(x, y, z)

Create new vector

Parameters:
  • x (number) – x component

  • y (number) – y component

  • z (number) – z component

Returns:

the new vector

Return type:

Vector3

set(x, y, z)

Set values of vector

Parameters:
  • x (number) – x component

  • y (number) – y component

  • z (number) – z component

get()

Get values of vector

Returns:

the values

Return type:

array

toData()

Get values of vector

Returns:

the values

Return type:

table

clone()

Clone the vector

Returns:

the clone

Return type:

Vector3

static distance(va, vb)

Calculate distance between 2 vectors

Parameters:
Returns:

distance between vectors

Return type:

number

static dot(lhs, rhs)

Calculate dot product of 2 vectors

Parameters:
Returns:

the dot product

Return type:

number

static lerp(from, to, t)

Linear iterpolation between 2 vectors

Parameters:
  • from (Vector3) – first vector

  • to (Vector3) – second vector

  • t (number) – value between 0 and 1 to determine which position between those vectors should be calculated

Returns:

interpolated vector

Return type:

Vector3

magnitude()

Calculate magnitude of the vector

Returns:

magnitue value

Return type:

number

static max(lhs, rhs)

Return the maximum values from both vectors for each component

Parameters:
Returns:

new Vector with the maximum values of each component

Return type:

Vector3

static min(lhs, rhs)

Return the minimum values from both vectors for each component

Parameters:
Returns:

new Vector with the minimum values of each component

Return type:

Vector3

normalized()

Return the normalized version of the vector

Returns:

normalized vector

Return type:

Vector3

normalize()

Normalize this vector

Returns:

returns itself

Return type:

Vector3

sqrMagnitude()

Return the squared magnitude of the vector

Returns:

squared magnitude

Return type:

number

static angle(from, to)

Calculate ange between vectors

Parameters:
Returns:

angle in degrees

Return type:

number

clampMagnitude(maxLength)

Checks the magnitude of the vector and if longer than maxLength, will clamp the vector

Parameters:

maxLength (number) – maximum length of vector

Returns:

returns itself

Return type:

Vector3

static orthoNormalize(va, vb, vc)

Orthonormalize 3 vectors

Parameters:
Returns:

Array of the three input vectors

Return type:

array

static scaled(a, b)

Scales vector by another vector

Parameters:
Returns:

scaled vector

Return type:

Vector3

scale(b)

Scales vector by another vector

Parameters:

b (Vector3) – the second vector

Returns:

returns itself

Return type:

Vector3

static cross(lhs, rhs)

Calculates cross product

Parameters:
Returns:

cross product

Return type:

Vector3

equals(other)

Checks if other vector is equal this one

Parameters:

other (Vector3) – the other vector

Returns:

comparison result

Return type:

boolean

static reflect(inDirection, inNormal)

Reflects the inDirection vector at the plane defined by inNormal

Parameters:
  • inDirection (Vector3) – direction vector to reflect

  • inNormal (Vector3) – normal of the plane

Returns:

reflected vector

Return type:

Vector3

static project(vector, onNormal)

Project vector onto a normal vector

Parameters:
  • vector (Vector3) – input vector

  • onNormal (Vector3) – normal vector

Returns:

projected vector

Return type:

Vector3

static projectOnPlane(vector, planeNormal)

Project vector onto plane

Parameters:
  • vector (Vector3) – input vector

  • planeNormal (Vector3) – plane normal

Returns:

projected vector

Return type:

Vector3

static slerp(from, to, t)

Perform spherical linear interpolation on vector

Parameters:
  • from (Vector3) – from vector

  • to (Vector3) – to vector

  • t (number) – number between 0 and 1 to determine which position should be interpolated

Returns:

interpolated vector

Return type:

Vector3

mul(q)

Multiply vector with a scalar or quaternion

Parameters:

q (number) – scalar or quaternion

Returns:

returns itself

Return type:

Vector3

div(d)

Divide vector by a scalar

Parameters:

d (number) – scalar

Returns:

returns itself

Return type:

Vector3

add(vb)

Adds a vector to this vector

Parameters:

vb (Vector3) – other vector

Returns:

returns itself

Return type:

Vector3

sub(vb)

Subtracts another vector from this vector

Parameters:

vb (Vector3) – other vector

Returns:

returns itself

Return type:

Vector3

mulQuat(quat)

Multiply quaternion with this vector

Parameters:

quat (Quaternion) – input quaternion

Returns:

returns itself

Return type:

Vector3

static createFrustumRays(viewDirection, fov, resX, resY)

Creates an array of Vector3 objects which are the direction vectors of the frustum as defined by the parameters

Parameters:
  • viewDirection (Vector3) – a view vector

  • fov (number) – Field of view value in degrees

  • resX (number) – resolution width. Needs to be at least 2

  • resY (number) – resolution height Needs to be at least 2

Returns:

Array of Vector3 objects which have the count width * height

Return type:

Array

Examples