Gets the number of bytes per component.
The number of bytes per component (4 for Float32Array, 8 for Float64Array)
Gets the class name.
The class name "Vector3"
Gets the GLSL representation of this vector as a float vec3.
A string representation suitable for GLSL shaders
Gets the GLSL representation of this vector as an integer ivec3.
A string representation suitable for GLSL shaders with integer components
Gets the W component of the vector (always returns 1 for homogeneous coordinates).
Always returns 1
Gets the WGSL representation of this vector as a float vec3f.
A string representation suitable for WGSL shaders
Gets the WGSL representation of this vector as an integer vec3i.
A string representation suitable for WGSL shaders with integer components
Gets the X component of the vector.
The X component value
Gets the Y component of the vector.
The Y component value
Gets the Z component of the vector.
The Z component value
StaticcompositionGets the composition type for this vector class.
The composition type (Vec3)
Gets the component at the specified index.
The index (0 for x, 1 for y, 2 for z)
The component value at the specified index
Creates a copy of this vector.
A new vector with the same components
Calculates the dot product of this vector with another vector.
The vector to calculate dot product with
The dot product result
Converts the vector to a flat array.
An array containing the x, y, and z components
Checks if this vector is a dummy vector (empty).
True if the vector is dummy (has no components), false otherwise
Checks if this vector is approximately equal to another vector within a tolerance.
The vector to compare with
The tolerance for comparison (default: Number.EPSILON)
True if vectors are approximately equal, false otherwise
Checks if this vector is strictly equal to another vector (exact comparison).
The vector to compare with
True if vectors are exactly equal, false otherwise
Checks if the internal storage shares the same ArrayBuffer as the provided one. Useful for determining if vectors share underlying memory.
The ArrayBuffer to compare against
True if the same ArrayBuffer is used, false otherwise
Calculates the length (magnitude) of the vector.
The length of the vector
Calculates the squared length of the vector. This is more efficient than calculating the actual length when only comparison is needed.
The squared length of the vector
Calculates the distance from this vector to another vector.
The target vector
The distance between the vectors
Converts the vector to a string representation.
A string representation of the vector in the format "(x, y, z)"
Converts the vector to an approximate string representation with limited decimal places.
A string representation with financial formatting
Gets the component value at the specified index. Alias for the at() method for convenience.
The index of the component to retrieve
The component value at the given index
Static_Adds two vectors component-wise (static version).
The first vector
The second vector
The typed array constructor to use
A new vector containing the sum
Static_Calculates the cross product of two vectors (static version).
The first vector (left operand)
The second vector (right operand)
The typed array constructor to use
A new vector containing the cross product result
Static_Divides a vector by a scalar value (static version).
The vector to divide
The scalar value to divide by
The typed array constructor to use
A new vector containing the divided result
Static_Divides two vectors component-wise (static version).
The vector to divide
The vector to divide by
The typed array constructor to use
A new vector containing the component-wise division result
Static_Creates an empty dummy vector for placeholder purposes.
The typed array constructor to use
A new dummy vector
Static_Creates a vector from individual x, y, z components.
The x component
The y component
The z component
The typed array constructor to use
A new vector
Static_Creates a vector from an array (takes first 3 elements).
The array containing the components
The typed array constructor to use
A new vector
Static_Creates a vector from a 3-element array.
The array containing x, y, z components
The typed array constructor to use
A new vector
Static_Creates a vector by copying from another Vector3.
The source vector to copy from
The typed array constructor to use
A new vector
Static_Creates a Vector3 from a Vector4 (drops the w component).
The source Vector4 to copy from
The typed array constructor to use
A new vector
Static_Creates a Vector3 from a Vector2 (sets z component to 0).
The source Vector2 to copy from
The typed array constructor to use
A new vector
Static_Performs linear interpolation between two vectors (static version).
The start vector
The end vector
The interpolation ratio (0.0 to 1.0)
The typed array constructor to use
A new vector containing the interpolated result
Static_Multiplies a vector by a scalar value (static version).
The vector to multiply
The scalar value to multiply by
The typed array constructor to use
A new vector containing the scaled result
Static_Transforms a 3D vector by a 4x4 matrix, treating the vector as a point (w=1). The result is perspective-divided if the w component is not 1.
The vector to transform
The 4x4 transformation matrix
The typed array constructor to use
A new transformed vector
Static_Transforms a vector by a quaternion rotation (static version). This applies the quaternion rotation to the vector.
The quaternion to apply
The vector to transform
The typed array constructor to use
A new vector containing the transformed result
Static_Multiplies two vectors component-wise (static version).
The first vector
The second vector
The typed array constructor to use
A new vector containing the component-wise product
Static_Normalizes a vector to unit length (static version).
The vector to normalize
The typed array constructor to use
A new normalized vector
Static_Creates a vector with all components set to 1 (1, 1, 1).
The typed array constructor to use
A new vector with all components set to 1
Static_Subtracts the second vector from the first vector (static version).
The vector to subtract from
The vector to subtract
The typed array constructor to use
A new vector containing the difference
Static_Creates a zero vector (0, 0, 0).
The typed array constructor to use
A new zero vector
StaticaddStaticaddAdds a scaled vector to another vector and stores the result in the output vector.
The vector to add to
The vector to add
The scale to apply to the second vector
The output vector to store the result
The output vector containing the sum
StaticaddAdds two vectors and stores the result in the output vector.
The first vector
The second vector
The output vector to store the result
The output vector containing the sum
StaticangleStaticcrossStaticcrossCalculates the cross product of two vectors and stores the result in the output vector.
The first vector (left operand)
The second vector (right operand)
The output vector to store the result
The output vector containing the cross product result
StaticdivideStaticdivideDivides a vector by a scalar and stores the result in the output vector.
The vector to divide
The scalar value to divide by
The output vector to store the result
The output vector containing the divided result
StaticdivideStaticdivideDivides two vectors component-wise and stores the result in the output vector.
The vector to divide
The vector to divide by
The output vector to store the result
The output vector containing the component-wise division result
StaticdotStaticdummyCreates an empty dummy vector for placeholder purposes.
A new dummy Vector3d instance
StaticfromCreates a vector from an ArrayBuffer.
The ArrayBuffer containing the vector data
A new Vector3d instance
StaticfromCreates a vector with all components set to the same value.
The value to set for all components
A new Vector3d instance
StaticfromCreates a vector from individual x, y, z components.
The x component
The y component
The z component
A new Vector3d instance
StaticfromCreates a vector from an array (takes first 3 elements).
The array containing the components
A new Vector3d instance
StaticfromStaticfromCreates a vector from a Float64Array.
The Float64Array containing the vector data
A new Vector3d instance
StaticlengthStaticlengthCalculates the squared length of a vector (static version). This is more efficient than calculating the actual length when only comparison is needed.
The vector to calculate squared length for
The squared length of the vector
StaticlerpStaticmultiplyStaticmultiplyStaticmultiplyTransforms a 3D vector by a 4x4 matrix, treating the vector as a point (w=1). The result is perspective-divided if the w component is not 1.
The vector to transform
The 4x4 transformation matrix
The output vector to store the result
A new transformed vector
StaticmultiplyTransforms a vector by a quaternion rotation.
The quaternion to apply
The vector to transform
A new Vector3d instance containing the transformed result
StaticmultiplyTransforms a vector by a quaternion rotation and stores the result in the output vector. This applies the quaternion rotation to the vector.
The quaternion to apply
The vector to transform
The output vector to store the result
The output vector containing the transformed result
StaticmultiplyMultiplies a vector by a scalar and stores the result in the output vector.
The vector to multiply
The scalar value to multiply by
The output vector to store the result
The output vector containing the scaled result
StaticmultiplyStaticmultiplyMultiplies two vectors component-wise and stores the result in the output vector.
The first vector
The second vector
The output vector to store the result
The output vector containing the component-wise product
StaticnormalizeStaticnormalizeNormalizes a vector and stores the result in the output vector.
The vector to normalize
The output vector to store the result
The output vector containing the normalized result
StaticoneCreates a vector with all components set to 1 (1, 1, 1).
A new Vector3d instance with all components set to 1
StaticsubtractStaticsubtractSubtracts two vectors and stores the result in the output vector.
The vector to subtract from
The vector to subtract
The output vector to store the result
The output vector containing the difference
StaticzeroCreates a zero vector (0, 0, 0).
A new Vector3d instance with all components set to 0
Immutable 3D vector class with 64-bit float components. This high-precision implementation is suitable for applications requiring double precision floating-point calculations, such as scientific computing or when dealing with very large coordinate systems.
Example