Vector3

A 3 dimensioanl vector.

Constructor

new L3D.Vector3()

Vector3() // [0, 0, 0]
Vector3(1) // [1, 1, 1]
Vector3(1, 2, 3) // [1, 2, 3]
Vector3([1, 2, 3]) // [1, 2, 3]
Vector3(Vector3) // Copy the vector
Parameters
arguments... *

Variable arguments

Extends

  • Float32Array

Properties

Get the axis that has the greatest absolute value.

isZero bool

True if the vector is all zeros.

x number

The x component.

y number

The y component.

z number

The z component.

static Back Vector3

Vector3(0, 0, 1)

static Down Vector3

Vector3(0, -1, 0)

static Front Vector3

Vector3(0, 0, -1)

static Left Vector3

Vector3(-1, 0, 0)

static One Vector3

Vector3(1, 1, 1)

static Right Vector3

Vector3(1, 0, 0)

static Up Vector3

Vector3(0, 1, 0)

static X Vector3

Vector3(1, 0, 0)

static Y Vector3

Vector3(0, 1, 0)

static Yoffset Vector3

Slightly offset from true Y, to reduce potential singularity error aligning Y to (0, -1, 0) with Matrix4.setAlignToVector.

static Z Vector3

Vector3(0, 0, 1)

static Zero Vector3

Vector3(0, 0, 0)

Methods

abs()Vector3

Make each component its absolute value, [abs(x), abs(y), abs(z)]

Returns
Vector3

Returns self.

add(b)Vector3

Add a vector to this, this + b.

Parameters
b Vector3
Returns
Vector3

Returns self.

clone()Vector3

Create a copy of this vector.

Returns
Vector3

divide(b)Vector3

Divide a vector to this, this / b.

Parameters
b Vector3
Returns
Vector3

Returns self.

getLength() → number

Returns the length of the vector.

Returns
number

getLengthSquared() → number

Returns the squared length of the vector.

Returns
number

map() → number|Vector2|Vector3

Map this vector to a new vector.

map(1) // Returns a number with the y value of this vector.
map(0, 2) // Returns a Vector2 as [x, z].
map(2, 1, 0) // Returns a Vector3 with as [z, y, x].
Parameters
arguments... number

The variable component indices to map.

Returns
number | Vector2 | Vector3

multiply(b)Vector3

Multiply a vector with this, this * b.

Parameters
b Vector3
Returns
Vector3

Returns self.

negate()Vector3

Negate the vector, as [-x, -y, -z].

Returns
Vector3

Returns self.

normalize()Vector3

Normalize the vector.

Returns
Vector3

Returns self.

remap(xi, yi, zi)Vector3

Remap the channels of this vector.

remap(1, 2, 0) // returns [y, z, x]
Parameters
xi number

The index of the channel to set x to.

yi number

The index of the channel to set y to.

zi number

The index of the channel to set z to.

Returns
Vector3

scale(s)Vector3

Scale the vector by a number, this * s.

Parameters
s number
Returns
Vector3

setFrom(x, y, z)Vector3

Set the components of this vector.

Parameters
x number | Array
y number
z number
Returns
Vector3

Returns this vector.

setZero()Vector3

Set all components to 0.

Returns
Vector3

Returns this vector.

subtract(b)Vector3

Subtract a vector from this, this - b.

Parameters
b Vector3
Returns
Vector3

Returns self.

sum() → number

Returns the sum of the components, x + y + z.

Returns
number

toArray() → Array

Convert the vector to an Array.

Returns
Array

toString() → String

Get the string representation of the vector.

Returns
String

static abs(a, out)Vector3

Return the absoluate value of a vector.

Parameters
a Vector3
out Vector3

Optional storage for the output.

Returns
Vector3

static add(a, b, out)Vector3

Add two vectors.

Parameters
a Vector3
b Vector3
out Vector3

Optional storage for the output.

Returns
Vector3

static cross(a, b, out)Vector3

Calculate the cross product of two vectors.

Parameters
a Vector3
b Vector3
out Vector3

Optional storage for the output.

Returns
Vector3

static distance(a, b) → number

Calculate the distance between two points.

Parameters
a Vector3
b Vector3
Returns
number

static distanceSquared(a, b) → number

Calculate the squared distance between two points.

Parameters
a Vector3
b Vector3
Returns
number

static divide(a, b, out)Vector3

Divide two vectors.

Parameters
a Vector3
b Vector3
out Vector3
Returns
Vector3

static dot(a, b) → number

Calculate the dot product of two vectors.

Parameters
a Vector3
b Vector3
Returns
number

static length(a) → number

Calculate the length of a vector.

Parameters
a Vector3
Returns
number

static lengthSquared(a) → number

Calculate the squared lenth of a vector.

Parameters
a Vector3
Returns
number

static lerp(a, b, t, out)Vector3

Linear interpolate between two vectors.

Parameters
a Vector3
b Vector3
t number

Interpolator between 0 and 1.

out Vector3

Optional storage for the output.

Returns
Vector3

static max(a, b, out)Vector3

Each component will be the maximum of either a or b.

Parameters
a Vector3
b Vector3
out Vector3

Optional storage for the output.

Returns
Vector3

static min(a, b, out)Vector3

Each component will be the minimum of either a or b.

Parameters
a Vector3
b Vector3
out Vector3

Optional storage for the output.

Returns
Vector3

static multiply(a, b, out)Vector3

Multiply two vectors

Parameters
a Vector3
b Vector3
out Vector3
Returns
Vector3

static negated(a, out)Vector3

Return the negated value of a vector.

Parameters
a Vector3
out Vector3

Optional storage for the output.

Returns
Vector3

static normalize(a, out)Vector3

Return the normalized version of the vector.

Parameters
a Vector3
out Vector3

Optional storage for the output.

Returns
Vector3

static project(a, b, out)Vector3

Project a onto b.

Parameters
a Vector3
b Vector3
out Vector3
Returns
Vector3

static reflect(direction, normal, out)Vector3

Reflect the direction vector against the normal.

Parameters
direction Vector3
normal Vector3
out Vector3
Returns
Vector3

static refract(incident, normal, eta, out)Vector3

Calculate the refraction vector against the surface normal, from IOR k1 to IOR k2.

Parameters
incident Vector3

Specifies the incident vector

normal Vector3

Specifies the normal vector

eta number

Specifies the ratio of indices of refraction

out Vector3

Optional output storage

Returns
Vector3

static scale(a, s, out)Vector3

Scale a vector by a number.

Parameters
a Vector3
s number
out Vector3
Returns
Vector3

static scaleAndAdd(a, b, s, out)Vector3

Scale and add two numbers, as out = a + b * s.

Parameters
a Vector3
b Vector3
s number
out Vector3
Returns
Vector3

static subtract(a, b, out)Vector3

Subtract two vectors

Parameters
a Vector3
b Vector3
out Vector3
Returns
Vector3