Vector3
A 3D vector with x, y, z components.
Constructor
const v = new Vector3(x, y, z) // defaults to (0, 0, 0)
Properties
x,y,z— Component valuesisVector3— Type flag (true)
Methods
Setting
set(x, y, z)— Set componentssetScalar(s)— Set all components tossetX(x),setY(y),setZ(z)— Set individual componentssetComponent(index, value)— Set by index (0=x, 1=y, 2=z)copy(v)— Copy from another Vector3fromArray(array, offset?)— Set from arrayfromBufferAttribute(attribute, index)— Set from buffer attributesetFromSpherical(s)/setFromSphericalCoords(radius, phi, theta)setFromCylindrical(c)/setFromCylindricalCoords(radius, theta, y)setFromMatrixPosition(m)— Extract position from Matrix4setFromMatrixScale(m)— Extract scale from Matrix4setFromMatrixColumn(m, index)— Extract column from Matrix4setFromMatrix3Column(m, index)— Extract column from Matrix3setFromEuler(e)— Set from Euler anglessetFromColor(c)— Set from Color (r→x, g→y, b→z)
Arithmetic
add(v),addScalar(s),addVectors(a, b),addScaledVector(v, s)sub(v),subScalar(s),subVectors(a, b)multiply(v),multiplyScalar(s),multiplyVectors(a, b)divide(v),divideScalar(s)negate()— Flip sign of all components
Transforms
applyMatrix3(m)— Multiply by 3x3 matrixapplyMatrix4(m)— Multiply by 4x4 matrix (with perspective divide)applyNormalMatrix(m)— Apply normal matrix and normalizeapplyQuaternion(q)— Apply quaternion rotationapplyEuler(euler)— Apply Euler rotationapplyAxisAngle(axis, angle)— Apply axis-angle rotationtransformDirection(m)— Transform as direction (no translation), then normalizeproject(camera)— World → NDCunproject(camera)— NDC → World
Geometry
dot(v)— Dot productcross(v)— Cross product (in-place)crossVectors(a, b)— Cross product of two vectorsprojectOnVector(v)— Project onto vectorprojectOnPlane(normal)— Project onto planereflect(normal)— Reflect off plane
Length & Distance
length(),lengthSq(),manhattanLength()distanceTo(v),distanceToSquared(v),manhattanDistanceTo(v)normalize()— Make unit lengthsetLength(length)— Set to specific length
Clamping & Rounding
min(v),max(v)— Component-wise min/maxclamp(min, max)— Clamp between two vectorsclampScalar(min, max)— Clamp all componentsclampLength(min, max)— Clamp vector lengthfloor(),ceil(),round(),roundToZero()
Interpolation
lerp(v, alpha)— Lerp towardvlerpVectors(v1, v2, alpha)— Lerp between two vectors
Other
angleTo(v)— Angle to another vector in radiansequals(v)— Equality testclone()— Return a copytoArray(array?, offset?)— Write to arrayrandom()— Random components in [0, 1)randomDirection()— Random point on unit spheregetComponent(index)— Get by index