mathue
    Preparing search index...

    Class Quaternion

    Represents a quaternion using Hamilton's notation: q = a + bi + cj + dk

    Implements

    Index

    Accessors

    • get a(): number

      Gets the first real component of this quaternion

      Returns number

      const q = new Quaternion(1, 2, 3, 4);
      console.log(q.a); // 1
    • get b(): number

      Gets the i-coefficient of this quaternion

      Returns number

      const q = new Quaternion(1, 2, 3, 4);
      console.log(q.b); // 2
    • get c(): number

      Gets the j-coefficient of this quaternion

      Returns number

      const q = new Quaternion(1, 2, 3, 4);
      console.log(q.c); // 3
    • get d(): number

      Gets the k-coefficient of this quaternion

      Returns number

      const q = new Quaternion(1, 2, 3, 4);
      console.log(q.d); // 4

    Constructors

    • Constructor of quaternion: q = a + bi + cj + dk

      Parameters

      • a: number

        the first real component

      • b: number

        the i-coefficient

      • c: number

        the j-coefficient

      • d: number

        the k-coefficient

      Returns Quaternion

      const q = new Quaternion(1, 0, 0, 0);
      

    Factory Methods

    • Parameters

      • axis: Vector3

        the rotation axis

      • angle: number

        the rotation angle in radians

      Returns Quaternion

      new normalized quaternion instance from axis and radian

      const axis = new Vector3(0, 1, 0);
      const radian = Math.PI / 3;
      const q = Quaternion.identity(axis, radian);

    Methods

    • Sets all components of this quaternion: q = a + bi + cj + dk (mutates this)

      Parameters

      • a: number

        the first real component

      • b: number

        the i-coefficient

      • c: number

        the j-coefficient

      • d: number

        the k-coefficient

      Returns Quaternion

      this instance, for method chaining

      const q = Quaternion.identity();
      console.log(q); // (1, 0, 0, 0)
      q.set(0, 0, 0, 1);
      console.log(q); // (0, 0, 0, 1)
    • Sets this quaternion to other quaternion (mutates this)

      Parameters

      Returns Quaternion

      this instance, for method chaining

      const q1 = new Quaternion(1, 2, 3, 4);
      const q2 = new Quaternion(5, 6, 7, 8);
      q1.copy(q2);
      console.log(q1); // (5, 6, 7, 8)
      console.log(q2); // (5, 6, 7, 8)
    • Sets this instance to identity quaternion (mutates this)

      Returns void

      this instance, for method chaining

      const q = new Quaternion(1, 2, 3, 4);
      q.setIdentity();
      console.log(q); // (1, 0, 0, 0)
    • Sets this quaternion from axis and radian (mutates this)

      Parameters

      • axis: Vector3

        the rotation axis

      • angle: number

        the rotation angle in radians

      Returns void

      this instance, for method chaining

      const q = Quaternion.identity();
      const axis = new Vector3(0, 1, 0);
      const radian = Math.PI / 3;
      q.setAxisAndAngle(axis, radian);
    • Calculates squared norm of this quaternion (pure)

      Returns number

      squared norm of this quaternion

      const q = new Quaternion(1, 2, 2, 4);
      console.log(q.squaredNorm()); // 25
    • Calculates norm of this quaternion (pure)

      Returns number

      norm of this quaternion

      const q = new Quaternion(1, 2, 2, 4);
      console.log(q.norm()); // 5
    • Calculates conjugate of this quaternion (mutates this)

      Returns Quaternion

      this instance, for method chaining

      const q = new Quaternion(1, 2, 3, 4);
      q.conjugate();
      console.log(q); // (1, -2, -3, -4)
    • Adds other quaternion to this instance (mutates this)

      Parameters

      Returns Quaternion

      this instance, for method chaining

      const q1 = new Quaternion(1, 2, 3, 4);
      const q2 = new Quaternion(5, 6, 7, 8);
      q1.add(q2);
      console.log(q1); // (6, 8, 10, 12)
      console.log(q2); // (5, 6, 7, 8)
    • Subtracts other quaternion from this instance (mutates this)

      Parameters

      Returns Quaternion

      this instance, for method chaining

      const q1 = new Quaternion(5, 6, 7, 8);
      const q2 = new Quaternion(1, 2, 3, 4);
      q1.subtract(q2);
      console.log(q1); // (4, 4, 4, 4)
      console.log(q2); // (1, 2, 3, 4)
    • Divides this instance by other quaternion (mutates this)

      Parameters

      Returns Quaternion | null

      this instance, for method chaining

      const q1 = new Quaternion(1, 2, 3, 4);
      const q2 = new Quaternion(5, 6, 7, 8);
      q1.divide(q2);
      console.log(q1); // (0.1333, 0.0667, 0.1, 0.1333)
      console.log(q2); // (5, 6, 7, 8)
    • Multiplies this quaternion by a scalar (mutates this)

      Parameters

      • scalar: number

        scalar value

      Returns Quaternion

      this instance, for method chaining

      const q = new Quaternion(1, 2, 3, 4);
      q.multiplyScalar(2);
      console.log(q); // (2, 4, 6, 8)
    • Divides this quaternion by a scalar (mutates this)

      Parameters

      • scalar: number

        scalar value

      Returns Quaternion

      this instance, for method chaining

      const q = new Quaternion(2, 4, 6, 8);
      q.divideScalar(2);
      console.log(q); // (1, 2, 3, 4)
    • Rotates this quaternion around X axis by given radian (mutates this)

      Parameters

      • radian: number

        the rotation angle in radians

      Returns Quaternion

      this instance, for method chaining

      const q = Quaternion.identity();
      q.rotateX(Math.PI / 2);
      console.log(q); // (0.7071, 0.7071, 0, 0)
    • Rotates this quaternion around Y axis by given radian (mutates this)

      Parameters

      • radian: number

        the rotation angle in radians

      Returns Quaternion

      this instance, for method chaining

      const q = Quaternion.identity();
      q.rotateY(Math.PI / 2);
      console.log(q); // (0.7071, 0, 0.7071, 0)
    • Rotates this quaternion around Z axis by given radian (mutates this)

      Parameters

      • radian: number

        the rotation angle in radians

      Returns Quaternion

      this instance, for method chaining

      const q = Quaternion.identity();
      q.rotateZ(Math.PI / 2);
      console.log(q); // (0.7071, 0, 0, 0.7071)