new Vector3(x, y, z)math3d.js:77Create a 3D vector
xnumber optional, default 0ynumber optional, default 0znumber optional, default 0
const a = vec3(1, 2, 3);
const b = a.add(vec3(0, 1, 0)).normalize();3D Vector object, right handed with Y up
new Vector3(x, y, z)math3d.js:77Create a 3D vector
x number optional, default 0y number optional, default 0z number optional, default 0const a = vec3(1, 2, 3);
const b = a.add(vec3(0, 1, 0)).normalize();x : numbermath3d.js:87X axis location
y : numbermath3d.js:89Y axis location
z : numbermath3d.js:91Z axis location
abs() → Vector3math3d.js:244Returns a new vector with the absolute value of each component
clampLength(length) → Vector3math3d.js:171Returns a new vector clamped to the length passed in
length number optional, default 1copy() → Vector3math3d.js:108Returns a new vector that is a copy of this
cross(v) → Vector3math3d.js:185Returns a vector at right angles to both this and the one passed in
v Vector3distance(v) → numbermath3d.js:152Returns the distance from this vector to the vector passed in
v Vector3distanceSquared(v) → numbermath3d.js:157Returns the distance squared from this vector to the vector passed in
v Vector3divide(v) → Vector3math3d.js:128Returns a copy of this vector divided by the vector passed in
v Vector3dot(v) → numbermath3d.js:180Returns the dot product of this vector and the vector passed in
v Vector3floor() → Vector3math3d.js:248Returns a new vector with each component floored
isValid() → booleanmath3d.js:275Checks if this is a valid vector
length() → numbermath3d.js:137Returns the length of this vector
lengthSquared() → numbermath3d.js:141Returns the length of this vector squared
lerp(v, percent) → Vector3math3d.js:197Returns a new vector interpolated between this and the vector passed in, percent is clamped to 0-1
v Vector3percent numbernormalize(length) → Vector3math3d.js:162Returns a new vector in the same direction with the length passed in, zero stays zero
length number optional, default 1reflect(normal, restitution) → Vector3math3d.js:147Returns a copy of this vector reflected by a surface normal
normal Vector3Surface normal, should be normalized
restitution number optional, default 1How much to bounce, 1 is a perfect bounce, 0 slides along the surface
rotate(axis, angle) → Vector3math3d.js:207Returns a new vector turned around an axis, counter clockwise when the axis points at you
axis Vector3Unit length
angle numberRadians
rotateX(angle) → Vector3math3d.js:218Returns a new vector turned around the X axis, the way a positive pitch in rotation3D turns things
angle numberRadians
rotateY(angle) → Vector3math3d.js:227Returns a new vector turned around the Y axis, the way a positive yaw in rotation3D turns things
angle numberRadians
rotateZ(angle) → Vector3math3d.js:236Returns a new vector turned around the Z axis, the way a positive roll in rotation3D turns things
angle numberRadians
round() → Vector3math3d.js:252Returns a new vector with each component rounded
set(x, y, z) → Vector3math3d.js:99Sets values of this vector and returns self
x number optional, default 0y number optional, default 0z number optional, default 0setFrom(v) → Vector3math3d.js:104Copies the values of another vector into this one and returns self
v Vector3snap(grid) → Vector3math3d.js:257Returns a new vector snapped down to a grid, grid is the number of steps per unit like Vector2.snap
grid numberSnap steps per unit, 2 snaps to halves
toString(digits) → stringmath3d.js:280Returns a string representation of this vector for debugging
digits number optional, default 3Number of digits to display
transform(matrix) → Vector3math3d.js:266Returns this point transformed by a matrix, translation included
matrix Matrix4transformDirection(matrix) → Vector3math3d.js:271Returns this direction transformed by a matrix, rotation and scale only
matrix Matrix4