t3d. Vector3

The vector 3 class.

Constructor

new Vector3(xopt, yopt, zopt)

Parameters:
NameTypeAttributesDefaultDescription
xNumber<optional>
0the x value of this vector. Default is 0.
yNumber<optional>
0the y value of this vector. Default is 0.
zNumber<optional>
0the z value of this vector. Default is 0.

Methods

add(v) → {t3d.Vector3}

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

addScalar(s) → {t3d.Vector3}

Adds the scalar value s to this vector's x, y and z values.
Parameters:
NameTypeDescription
sNumber
Returns:
Type: 
t3d.Vector3

addScaledVector(v, s) → {t3d.Vector3}

Adds the multiple of v and s to this vector.
Parameters:
NameTypeDescription
vt3d.Vector3
sNumber
Returns:
Type: 
t3d.Vector3

addVectors(a, b) → {t3d.Vector3}

Sets this vector to a + b.
Parameters:
NameTypeDescription
at3d.Vector3
bt3d.Vector3
Returns:
Type: 
t3d.Vector3

applyMatrix3(m) → {t3d.Vector3}

Multiplies this vector by m
Parameters:
NameTypeDescription
mt3d.Matrix3
Returns:
Type: 
t3d.Vector3

applyMatrix4(m) → {t3d.Vector3}

Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective.
Parameters:
NameTypeDescription
mt3d.Matrix4
Returns:
Type: 
t3d.Vector3

applyQuaternion(q) → {t3d.Vector3}

Applies a Quaternion transform to this vector.
Parameters:
NameTypeDescription
qt3d.Quaternion
Returns:
Type: 
t3d.Vector3

clone() → {t3d.Vector3}

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

copy(v) → {t3d.Vector3}

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

cross(v) → {t3d.Vector3}

Sets this vector to cross product of itself and v.
Parameters:
NameTypeDescription
vt3d.Vector3
Returns:
Type: 
t3d.Vector3

crossVectors(a, b) → {t3d.Vector3}

Sets this vector to cross product of a and b.
Parameters:
NameTypeDescription
at3d.Vector3
bt3d.Vector3
Returns:
Type: 
t3d.Vector3

distanceTo(v) → {Number}

Computes the distance from this vector to v.
Parameters:
NameTypeDescription
vt3d.Vector3
Returns:
Type: 
Number

distanceToSquared(v) → {Number}

Computes the squared distance from this vector to v. If you are just comparing the distance with another distance, you should compare the distance squared instead as it is slightly more efficient to calculate.
Parameters:
NameTypeDescription
vt3d.Vector3
Returns:
Type: 
Number

dot(a) → {Number}

Calculate the dot product of this vector and v.
Parameters:
NameTypeDescription
at3d.Vector3
Returns:
Type: 
Number

equals(v) → {Boolean}

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

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

Sets this vector's x value to be array[ offset + 0 ], y value to be array[ offset + 1 ] and z value to be array[ offset + 2 ].
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.Vector3

getLength() → {Number}

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

getLengthSquared() → {Number}

Computes the square of the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z). 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

lerp(v, alpha) → {t3d.Vector3}

Linearly interpolate between this vector and v, where alpha is the percent distance along the line - alpha = 0 will be this vector, and alpha = 1 will be v.
Parameters:
NameTypeDescription
vt3d.Vector3
alphaNumber
Returns:
Type: 
t3d.Vector3

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

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.Vector3
v2t3d.Vector3
ratioNumber
Returns:
Type: 
t3d.Vector3

max(v) → {t3d.Vector3}

If this vector's x, y or z value is less than v's x, y or z value, replace that value with the corresponding max value.
Parameters:
NameTypeDescription
vt3d.Vector3
Returns:
Type: 
t3d.Vector3

min(v) → {t3d.Vector3}

If this vector's x, y or z value is greater than v's x, y or z value, replace that value with the corresponding min value.
Parameters:
NameTypeDescription
vt3d.Vector3
Returns:
Type: 
t3d.Vector3

multiply(v) → {t3d.Vector3}

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

multiplyScalar(scalar) → {t3d.Vector3}

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

negate() → {t3d.Vector3}

Inverts this vector - i.e. sets x = -x, y = -y and z = -z.
Returns:
Type: 
t3d.Vector3

normalize(thicknessopt)

Convert this vector to a unit vector - that is, sets it equal to a vector with the same direction as this one, but length 1.
Parameters:
NameTypeAttributesDefaultDescription
thicknessNumber<optional>
1

project(camera) → {t3d.Vector3}

Projects this vector from world space into the camera's normalized device coordinate (NDC) space.
Parameters:
NameTypeDescription
camerat3d.Camera
Returns:
Type: 
t3d.Vector3

reflect(narmal) → {t3d.Vector3}

Reflect this vector off of plane orthogonal to normal. Normal is assumed to have unit length.
Parameters:
NameTypeDescription
narmalt3d.Vector3the normal to the reflecting plane
Returns:
Type: 
t3d.Vector3

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

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

setFromMatrixColumn(m, index) → {t3d.Vector3}

Sets this vector's x, y and z components from index column of matrix.
Parameters:
NameTypeDescription
mt3d.Matrix3
indexNumber
Returns:
Type: 
t3d.Vector3

setFromMatrixPosition(m) → {t3d.Vector3}

Sets this vector to the position elements of the transformation matrix m.
Parameters:
NameTypeDescription
mt3d.Matrix4
Returns:
Type: 
t3d.Vector3

setFromMatrixScale(m) → {t3d.Vector3}

Sets this vector to the scale elements of the transformation matrix m.
Parameters:
NameTypeDescription
mt3d.Matrix4
Returns:
Type: 
t3d.Vector3

setFromSpherical(s) → {t3d.Vector3}

Sets this vector from the spherical coordinates s.
Parameters:
NameTypeDescription
st3d.Spherical
Returns:
Type: 
t3d.Vector3

setScalar(scalar) → {t3d.Vector3}

Set the x, y and z values of this vector both equal to scalar.
Parameters:
NameTypeDescription
scalarNumber
Returns:
Type: 
t3d.Vector3

sub(v) → {t3d.Vector3}

Subtracts v from this vector.
Parameters:
NameTypeDescription
vt3d.Vector3
Returns:
Type: 
t3d.Vector3

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

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

subtract(a, targetopt) → {t3d.Vector3}

Subtracts a from this vector.
Parameters:
NameTypeAttributesDescription
at3d.Vector3
targett3d.Vector3<optional>
Returns:
Type: 
t3d.Vector3

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

Returns an array [x, y, z], or copies x, y and z 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>

transformDirection(m) → {t3d.Vector3}

Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) and then
Parameters:
NameTypeDescription
mt3d.Matrix4
Returns:
Type: 
t3d.Vector3

unproject(camera) → {t3d.Vector3}

Projects this vector from the camera's normalized device coordinate (NDC) space into world space.
Parameters:
NameTypeDescription
camerat3d.Camera
Returns:
Type: 
t3d.Vector3