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.

const v1 = Vector3d.fromCopy3(1.123456789, 2.987654321, 3.456789123);
const v2 = Vector3d.fromCopy3(4.111111111, 5.222222222, 6.333333333);
const sum = Vector3d.add(v1, v2);

Hierarchy (view full)

  • Vector3_<Float64ArrayConstructor>
    • Vector3d

Properties

_v: TypedArray = ...

Internal typed array storage for vector components

Accessors

  • get bytesPerComponent(): number
  • Gets the number of bytes per component.

    Returns number

    The number of bytes per component (4 for Float32Array, 8 for Float64Array)

  • get className(): string
  • Gets the class name.

    Returns string

    The class name "Vector3"

  • get glslStrAsFloat(): string
  • Gets the GLSL representation of this vector as a float vec3.

    Returns string

    A string representation suitable for GLSL shaders

  • get glslStrAsInt(): string
  • Gets the GLSL representation of this vector as an integer ivec3.

    Returns string

    A string representation suitable for GLSL shaders with integer components

  • get w(): number
  • Gets the W component of the vector (always returns 1 for homogeneous coordinates).

    Returns number

    Always returns 1

  • get wgslStrAsFloat(): string
  • Gets the WGSL representation of this vector as a float vec3f.

    Returns string

    A string representation suitable for WGSL shaders

  • get wgslStrAsInt(): string
  • Gets the WGSL representation of this vector as an integer vec3i.

    Returns string

    A string representation suitable for WGSL shaders with integer components

  • get x(): number
  • Gets the X component of the vector.

    Returns number

    The X component value

  • get y(): number
  • Gets the Y component of the vector.

    Returns number

    The Y component value

  • get z(): number
  • Gets the Z component of the vector.

    Returns number

    The Z component value

  • get compositionType(): CompositionTypeClass<"VEC3">
  • Gets the composition type for this vector class.

    Returns CompositionTypeClass<"VEC3">

    The composition type (Vec3)

Methods

  • Gets the component at the specified index.

    Parameters

    • i: number

      The index (0 for x, 1 for y, 2 for z)

    Returns number

    The component value at the specified index

  • Calculates the dot product of this vector with another vector.

    Parameters

    • vec: IVector3

      The vector to calculate dot product with

    Returns number

    The dot product result

  • Checks if this vector is approximately equal to another vector within a tolerance.

    Parameters

    • vec: IVector3

      The vector to compare with

    • delta: number = Number.EPSILON

      The tolerance for comparison (default: Number.EPSILON)

    Returns boolean

    True if vectors are approximately equal, false otherwise

  • Checks if this vector is strictly equal to another vector (exact comparison).

    Parameters

    • vec: IVector3

      The vector to compare with

    Returns boolean

    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.

    Parameters

    • arrayBuffer: ArrayBuffer

      The ArrayBuffer to compare against

    Returns boolean

    True if the same ArrayBuffer is used, false otherwise

  • Calculates the squared length of the vector. This is more efficient than calculating the actual length when only comparison is needed.

    Returns number

    The squared length of the vector

  • Gets the component value at the specified index. Alias for the at() method for convenience.

    Parameters

    • i: number

      The index of the component to retrieve

    Returns number

    The component value at the given index

  • Calculates the angle between two vectors in radians.

    Parameters

    Returns number

    The angle between the vectors in radians

    Error if either vector has zero length

  • Creates a vector from an ArrayBuffer.

    Parameters

    • arrayBuffer: ArrayBuffer

      The ArrayBuffer containing the vector data

    Returns Vector3d

    A new Vector3d instance

  • Creates a vector from individual x, y, z components.

    Parameters

    • x: number

      The x component

    • y: number

      The y component

    • z: number

      The z component

    Returns Vector3d

    A new Vector3d instance

  • Creates a vector from a Float64Array.

    Parameters

    • float64Array: Float64Array

      The Float64Array containing the vector data

    Returns Vector3d

    A new Vector3d instance

  • Calculates the squared length of a vector (static version). This is more efficient than calculating the actual length when only comparison is needed.

    Parameters

    • vec: IVector3

      The vector to calculate squared length for

    Returns number

    The squared length of the vector

  • Performs linear interpolation between two vectors.

    Parameters

    • lhs: IVector3

      The start vector

    • rhs: IVector3

      The end vector

    • ratio: number

      The interpolation ratio (0.0 to 1.0)

    Returns Vector3d

    A new Vector3d instance containing the interpolated result