Theme:

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 values
  • isVector3 — Type flag (true)

Methods

Setting

  • set(x, y, z) — Set components
  • setScalar(s) — Set all components to s
  • setX(x), setY(y), setZ(z) — Set individual components
  • setComponent(index, value) — Set by index (0=x, 1=y, 2=z)
  • copy(v) — Copy from another Vector3
  • fromArray(array, offset?) — Set from array
  • fromBufferAttribute(attribute, index) — Set from buffer attribute
  • setFromSpherical(s) / setFromSphericalCoords(radius, phi, theta)
  • setFromCylindrical(c) / setFromCylindricalCoords(radius, theta, y)
  • setFromMatrixPosition(m) — Extract position from Matrix4
  • setFromMatrixScale(m) — Extract scale from Matrix4
  • setFromMatrixColumn(m, index) — Extract column from Matrix4
  • setFromMatrix3Column(m, index) — Extract column from Matrix3
  • setFromEuler(e) — Set from Euler angles
  • setFromColor(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 matrix
  • applyMatrix4(m) — Multiply by 4x4 matrix (with perspective divide)
  • applyNormalMatrix(m) — Apply normal matrix and normalize
  • applyQuaternion(q) — Apply quaternion rotation
  • applyEuler(euler) — Apply Euler rotation
  • applyAxisAngle(axis, angle) — Apply axis-angle rotation
  • transformDirection(m) — Transform as direction (no translation), then normalize
  • project(camera) — World → NDC
  • unproject(camera) — NDC → World

Geometry

  • dot(v) — Dot product
  • cross(v) — Cross product (in-place)
  • crossVectors(a, b) — Cross product of two vectors
  • projectOnVector(v) — Project onto vector
  • projectOnPlane(normal) — Project onto plane
  • reflect(normal) — Reflect off plane

Length & Distance

  • length(), lengthSq(), manhattanLength()
  • distanceTo(v), distanceToSquared(v), manhattanDistanceTo(v)
  • normalize() — Make unit length
  • setLength(length) — Set to specific length

Clamping & Rounding

  • min(v), max(v) — Component-wise min/max
  • clamp(min, max) — Clamp between two vectors
  • clampScalar(min, max) — Clamp all components
  • clampLength(min, max) — Clamp vector length
  • floor(), ceil(), round(), roundToZero()

Interpolation

  • lerp(v, alpha) — Lerp toward v
  • lerpVectors(v1, v2, alpha) — Lerp between two vectors

Other

  • angleTo(v) — Angle to another vector in radians
  • equals(v) — Equality test
  • clone() — Return a copy
  • toArray(array?, offset?) — Write to array
  • random() — Random components in [0, 1)
  • randomDirection() — Random point on unit sphere
  • getComponent(index) — Get by index