Skip to main content

Vector3

Vector3

Kind: global class
Author: Alex Goldring
Copyright: Alex Goldring 2015-2024

new Vector3([x], [y], [z])

ParamTypeDefault
[x]number0
[y]number0
[z]number0

vector3.x : number

Kind: instance property of Vector3

vector3.y : number

Kind: instance property of Vector3

vector3.z : number

Kind: instance property of Vector3

vector3.onChanged : Signal.<number, number, number, number, number, number>

Kind: instance property of Vector3
Read only: true

vector3.asArray

Deprecated

Kind: instance property of Vector3

vector3.isVector3 : boolean

Kind: instance property of Vector3
Read only: true

vector3.readFromArray(array, offset)

Kind: instance method of Vector3

ParamTypeDefault
arrayArray.<number> | Float32Array
offsetnumber0

vector3.writeToArray(array, offset)

Kind: instance method of Vector3

ParamTypeDefault
arrayArray.<number> | Float32Array
offsetnumber0

vector3.set(x, y, z) ⇒ Vector3

Kind: instance method of Vector3

ParamType
xNumber
yNumber
zNumber

vector3.setScalar(v)

Kind: instance method of Vector3

ParamType
vnumber

vector3.setX(v) ⇒ Vector3

Kind: instance method of Vector3

ParamType
vnumber

vector3.setY(v) ⇒ Vector3

Kind: instance method of Vector3

ParamType
vnumber

vector3.setZ(v) ⇒ Vector3

Kind: instance method of Vector3

ParamType
vnumber

vector3.setXY(x, y) ⇒ Vector3

Kind: instance method of Vector3

ParamType
xnumber
ynumber

vector3.setXZ(x, z) ⇒ Vector3

Kind: instance method of Vector3

ParamType
xnumber
znumber

vector3.setYZ(y, z) ⇒ Vector3

Kind: instance method of Vector3

ParamType
ynumber
znumber

vector3.addVectors(a, b)

Kind: instance method of Vector3

ParamType
aVector3
bVector3

vector3.add(other) ⇒ Vector3

Kind: instance method of Vector3

ParamType
otherVector3

vector3._add(x, y, z) ⇒ Vector3

Kind: instance method of Vector3

ParamType
xNumber
yNumber
zNumber

vector3.subVectors(a, b)

Kind: instance method of Vector3

ParamType
aVector3
bVector3

vector3.sub(other) ⇒ Vector3

Kind: instance method of Vector3

ParamType
otherVector3

vector3._sub(x, y, z) ⇒ Vector3

Kind: instance method of Vector3

ParamType
xNumber
yNumber
zNumber

vector3._multiply(x, y, z) ⇒ Vector3

Kind: instance method of Vector3

ParamType
xNumber
yNumber
zNumber

vector3.multiply(other) ⇒ Vector3

Kind: instance method of Vector3

ParamType
otherVector3

vector3.multiplyVectors(a, b)

Kind: instance method of Vector3

ParamType
aVector3
bVector3

vector3._divide(x, y, z) ⇒ Vector3

Kind: instance method of Vector3

ParamType
xnumber
ynumber
znumber

vector3.divide(other) ⇒ Vector3

Kind: instance method of Vector3

ParamType
otherVector3

vector3.subScalar(val) ⇒ Vector3

Subtract scalar value from each component of the vector

Kind: instance method of Vector3

ParamType
valnumber

vector3.addScalar(val) ⇒ Vector3

Add a scalar value to each component of the vector

Kind: instance method of Vector3

ParamType
valnumber

vector3.clone() ⇒ Vector3

Kind: instance method of Vector3

vector3.multiplyScalar(val) ⇒ Vector3

Kind: instance method of Vector3

ParamType
valnumber

vector3.isZero() ⇒ boolean

Kind: instance method of Vector3

vector3.cross(other) ⇒ Vector3

Compute cross-product of two vectors. Result is written to this vector.

Kind: instance method of Vector3

ParamType
otherVector3

vector3.crossVectors(first, second)

Kind: instance method of Vector3

ParamType
firstVector3
secondVector3

vector3._crossVectors(ax, ay, az, bx, by, bz)

Kind: instance method of Vector3

ParamType
axnumber
aynumber
aznumber
bxnumber
bynumber
bznumber

vector3.abs() ⇒ Vector3

Sets all components of the vector to absolute value (positive)

Kind: instance method of Vector3

vector3.dot(v) ⇒ number

Kind: instance method of Vector3

ParamType
vVector3

vector3.length() ⇒ number

Computes length(magnitude) of the vector

Kind: instance method of Vector3

vector3.lengthSqr() ⇒ number

Computes squared length(magnitude) of the vector. Note: this operation is faster than computing length, because it doesn't involve computing square root

Kind: instance method of Vector3

vector3.normalize()

Normalizes the vector, preserving its direction, but making magnitude equal to 1

Kind: instance method of Vector3

vector3.isNormalized([squaredError]) ⇒ boolean

Kind: instance method of Vector3

ParamTypeDefault
[squaredError]number0.00001

vector3.copy(other) ⇒ Vector3

Kind: instance method of Vector3

ParamType
otherVector3 | Object

vector3.negate() ⇒ Vector3

Negates every component of the vector making it {-x, -y, -z}

Kind: instance method of Vector3

vector3.distanceTo(other) ⇒ number

Kind: instance method of Vector3

ParamType
otherVector3

vector3._distanceTo(x, y, z) ⇒ number

Kind: instance method of Vector3

ParamType
xnumber
ynumber
znumber

vector3.distanceSqrTo(other)

Squared distance between this vector and another. It is faster than computing real distance because no SQRT operation is needed.

Kind: instance method of Vector3

ParamTypeDescription
otherVector3returns {number}

vector3._distanceSqrTo(x, y, z) ⇒ number

Kind: instance method of Vector3

ParamType
xnumber
ynumber
znumber

vector3.angleTo(other) ⇒ number

Angle between two vectors (co-planar) in radians

Kind: instance method of Vector3

ParamType
otherVector3

vector3.applyQuaternion(q)

Kind: instance method of Vector3

ParamType
qQuaternion

vector3.sign() ⇒ Vector3

Set components X,Y,Z to values 1,0 or -1 based on the sign of their original value.

Kind: instance method of Vector3
Example

new Vector(5,0,-10).sign().equals(new Vector(1,0,-1)); //true

vector3.lerp(other, fraction) ⇒ Vector3

Linear interpolation

Kind: instance method of Vector3

ParamTypeDescription
otherVector3
fractionNumberbetween 0 and 1

vector3.lerpVectors(a, b, fraction)

Kind: instance method of Vector3

ParamType
aVector3
bVector3
fractionnumber

vector3.slerpVectors(a, b, fraction)

Spherical linear interpolation

Kind: instance method of Vector3

ParamType
aVector3
bVector3
fractionnumber

vector3.applyMatrix4_three(matrix4)

Deprecated

Kind: instance method of Vector3

ParamType
matrix4THREE.Matrix4

vector3.applyMatrix4(m4)

Kind: instance method of Vector3

ParamType
m4ArrayLike.<number> | Array.<number> | Float32Array

vector3.applyDirectionMatrix4(m4)

Assume current vector holds a direction, transform using a matrix to produce a new directional unit vector

Kind: instance method of Vector3

ParamType
m4ArrayLike.<number> | Array.<number> | Float32Array

vector3.transformDirection_three(m)

Deprecated

Kind: instance method of Vector3

ParamType
mTHREE.Matrix4

vector3.applyMatrix3_three(m) ⇒ Vector3

Deprecated

Kind: instance method of Vector3

ParamType
mTHREE.Matrix3

vector3.applyMatrix3(mat)

Kind: instance method of Vector3

ParamType
matArray.<number> | Float32Array

vector3.threejs_setFromMatrixPosition(matrix4)

Deprecated

Kind: instance method of Vector3

ParamType
matrix4THREE.Matrix4

vector3.setFromMatrixPosition(matrix4)

Kind: instance method of Vector3

ParamTypeDescription
matrix4ArrayLike.<number> | Array.<number> | Float32Array4x4 transform matrix

vector3.equals(other) ⇒ boolean

Kind: instance method of Vector3

ParamType
otherVector3

vector3._equals(x, y, z) ⇒ boolean

Kind: instance method of Vector3

ParamType
xnumber
ynumber
znumber

vector3.roughlyEquals(other, [tolerance]) ⇒ boolean

Kind: instance method of Vector3

ParamType
otherVector3
[tolerance]number

vector3._roughlyEquals(x, y, z, [tolerance]) ⇒ boolean

Kind: instance method of Vector3

ParamTypeDescription
xnumber
ynumber
znumber
[tolerance]numberacceptable deviation

vector3.projectOntoVector3(other)

Project this vector onto another

Kind: instance method of Vector3

ParamType
otherVector3

vector3._projectVectors(x0, y0, z0, x1, y1, z1)

Project first vector onto second one

Kind: instance method of Vector3

ParamType
x0number
y0number
z0number
x1number
y1number
z1number

vector3.setFromSphericalCoords(radius, phi, theta)

Convert spherical coordinates to cartesian

Kind: instance method of Vector3

ParamTypeDescription
radiusnumber
phinumberAlso known as Azimuth
thetanumberAlso known as Elevation

vector3.process(processor, [thisArg]) ⇒ Vector3

Kind: instance method of Vector3

ParamType
processorfunction
[thisArg]*

vector3.fromJSON(json)

Kind: instance method of Vector3

ParamType
jsonObject | number

vector3.toBinaryBuffer(buffer)

Deprecated

Kind: instance method of Vector3

ParamType
bufferBinaryBuffer

vector3.fromBinaryBuffer(buffer)

Deprecated

Kind: instance method of Vector3

ParamType
bufferBinaryBuffer

vector3.toBinaryBufferFloat32(buffer)

Deprecated

Kind: instance method of Vector3

ParamType
bufferBinaryBuffer

vector3.fromBinaryBufferFloat32(buffer)

Deprecated

Kind: instance method of Vector3

ParamType
bufferBinaryBuffer

Vector3.zero : Vector3

Kind: static property of Vector3
Read only: true

Vector3.one : Vector3

Useful for setting scale

Kind: static property of Vector3
Read only: true

Vector3.minus_one : Vector3

Useful for setting scale

Kind: static property of Vector3
Read only: true

Vector3.up : Vector3

Kind: static property of Vector3
Read only: true

Vector3.down : Vector3

Kind: static property of Vector3
Read only: true

Vector3.left : Vector3

Kind: static property of Vector3
Read only: true

Vector3.right : Vector3

Kind: static property of Vector3
Read only: true

Vector3.forward : Vector3

Kind: static property of Vector3
Read only: true

Vector3.back : Vector3

Kind: static property of Vector3
Read only: true

Vector3.typeName : string

Kind: static property of Vector3
Read only: true

Vector3.dot(a, b) ⇒ number

Dot product

Kind: static method of Vector3

ParamType
aVector3 | Vector4
bVector3 | Vector4

Vector3.distance(a, b) ⇒ number

Kind: static method of Vector3

ParamType
aVector3
bVector3

Vector3.fromArray(input, [offset]) ⇒ Vector3

Kind: static method of Vector3

ParamTypeDefault
inputArray.<number>
[offset]number0

Vector3.fromScalar(value) ⇒ Vector3

Kind: static method of Vector3

ParamType
valuenumber