t3d. Vector4

The vector 4 class

Constructor

new Vector4(xopt, yopt, zopt, wopt)

Parameters:
NameTypeAttributesDefaultDescription
xNumber<optional>
0the x value of this vector.
yNumber<optional>
0the y value of this vector.
zNumber<optional>
0the z value of this vector.
wNumber<optional>
1the w value of this vector.

Methods

add(v) → {t3d.Vector4}

Adds v to this vector.
Parameters:
NameTypeDescription
vt3d.Vector4
Returns:
Type: 
t3d.Vector4

applyMatrix4(m) → {t3d.Vector4}

Multiplies this vector by 4 x 4 m.
Parameters:
NameTypeDescription
mt3d.Matrix4
Returns:
Type: 
t3d.Vector4

clone() → {t3d.Vector4}

Returns a new Vector4 with the same x, y, z and w values as this one.
Returns:
Type: 
t3d.Vector4

copy(v) → {t3d.Vector4}

Copies the values of the passed Vector4's x, y, z and w properties to this Vector4.
Parameters:
NameTypeDescription
vt3d.Vector4
Returns:
Type: 
t3d.Vector4

dot(v) → {t3d.Vector4}

Calculates the dot product of this vector and v.
Parameters:
NameTypeDescription
vt3d.Vector4
Returns:
Type: 
t3d.Vector4

equals(v) → {Boolean}

Checks for strict equality of this vector and v.
Parameters:
NameTypeDescription
vt3d.Vector4
Returns:
Type: 
Boolean

fromArray(array, offsetopt, denormalizeopt) → {t3d.Vector4}

Sets this vector's x value to be array[ offset + 0 ], y value to be array[ offset + 1 ] z value to be array[ offset + 2 ] and w value to be array[ offset + 3 ].
Parameters:
NameTypeAttributesDefaultDescription
arrayArray.<Number>the source array.
offsetNumber<optional>
0offset into the array.
denormalizeBoolean<optional>
falseif true, denormalize the values, and array should be a typed array.
Returns:
Type: 
t3d.Vector4

getLength() → {Number}

Computes the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w).
Returns:
Type: 
Number

getLengthSquared() → {Number}

Computes the square of the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
Returns:
Type: 
Number

getManhattanLength() → {Number}

Computes the Manhattan length from (0, 0, 0, 0) to (x, y, z, w).
Returns:
Type: 
Number

lerpVectors(v1, v2, ratio) → {t3d.Vector4}

Sets this vector to be the vector linearly interpolated between v1 and v2 where ratio is the percent distance along the line connecting the two vectors - ratio = 0 will be v1, and ratio = 1 will be v2.
Parameters:
NameTypeDescription
v1t3d.Vector4the starting Vector4.
v2t3d.Vector4Vector4 to interpolate towards.
ratioNumberinterpolation factor, typically in the closed interval [0, 1].
Returns:
Type: 
t3d.Vector4

multiply(v) → {t3d.Vector4}

Multiplies this vector by v.
Parameters:
NameTypeDescription
vt3d.Vector4
Returns:
Type: 
t3d.Vector4

multiplyScalar(scalar) → {t3d.Vector4}

Multiplies this vector by scalar s.
Parameters:
NameTypeDescription
scalarNumber
Returns:
Type: 
t3d.Vector4

normalize() → {t3d.Vector4}

Converts this vector to a unit vector - that is, sets it equal to a vector with the same direction as this one, but length 1.
Returns:
Type: 
t3d.Vector4

set(x, y, z, w) → {t3d.Vector4}

Sets the x, y, z and w components of this vector.
Parameters:
NameTypeDefaultDescription
xNumber0
yNumber0
zNumber0
wNumber1
Returns:
Type: 
t3d.Vector4

subVectors(a, b) → {t3d.Vector4}

Sets this vector to a - b.
Parameters:
NameTypeDescription
at3d.Vector4
bt3d.Vector4
Returns:
Type: 
t3d.Vector4

toArray(arrayopt, offsetopt, normalizeopt) → {Array.<Number>}

Returns an array [x, y, z, w], or copies x, y, z and w into the provided array.
Parameters:
NameTypeAttributesDefaultDescription
arrayArray.<Number><optional>
array to store this vector to. If this is not provided, a new array will be created.
offsetNumber<optional>
0offset into the array.
normalizeBoolean<optional>
falseif true, normalize the values, and array should be a typed array.
Returns:
Type: 
Array.<Number>