zmath.quaternion

A Quaternion it's used to store a space orientation / rotation, and makes easy to interpolate rotations, at same time that avoid grimbal locks that have using Euler angles

  • Declaration

    alias Qua_f = Quaternion!float.Quaternion;

    Alias of a Quaternion with floats

  • Declaration

    alias Qua_d = Quaternion!double.Quaternion;

    Alias of a Quaternion with doubles

  • Declaration

    alias Qua_r = Quaternion!real.Quaternion;

    Alias of a Quaternion with reals

  • Declaration

    struct Quaternion(T = floatt) if (__traits(isFloating, T));

    Quaternion over a FloatPoint type,

    • dim

      Declaration

      static enum size_t dim;

      Quaternion Dimension

    • i

      Declaration

      T i;

      i complex component

    • j

      Declaration

      T j;

      j complex component

    • k

      Declaration

      T k;

      k complex component

    • w

      Declaration

      T w;

      w real component

    • x

      Declaration

      T x;

      alias of i component

    • y

      Declaration

      T y;

      alias of j component

    • z

      Declaration

      T z;

      alias of k component

    • Declaration

      this(in T i, in T j, in T k, in T w);

      Build a new Quaternion from a set of initial values

      Parameters

      T i

      i imaginary component

      T j

      j imaginary component

      T k

      k imaginary component

      T w

      i real component

    • Declaration

      this(in T[] xs);

      Build a new Quaternion from a array If no there values for j, and k, will be set to 0. w is set to 1

      Parameters

      T[] xs

      Array with coords

    • Declaration

      pure @nogc this(in Vector!(T, 3) vec);

      Build a new Quaternion from a 3D Vector w will be set to 1

      Parameters

      Vector!(T, 3) vec

      Vector 3d

    • Declaration

      pure @nogc this(in Vector!(T, 4) vec);

      Build a new Quaternion from a 4D Vector

      Parameters

      Vector!(T, 4) vec

      Vector 4d

    • Declaration

      @nogc this(U)(Vector!(T, 3) v, U angle) if (is(U : real));

      Creates a Quaternion from a 3d Vector and angle

      Parameters

      Vector!(T, 3) v

      Rotation axis

      U angle

      Rotation angle in radians

      Return Value

      Quaternion that represents a rotation

    • Declaration

      @nogc this(U)(U roll, U pitch, U yaw) if (__traits(isFloating, U));

      Creates a new Quaternion from Euler angles Params : roll = Rotation around X axis in radians (aka bank) pitch = Rotation around Y axis in radians (aka attitude) yaw = Rotation around Z axis in radians (aka heading)

      Return Value

      Quaternion that represents a rotation

    • Declaration

      const pure @nogc T opIndex(size_t i);

      Returns i coord of this vector

    • Declaration

      @nogc void opIndexAssign(T c, size_t i);

      Assigns a value to a coord

    • Declaration

      const pure @nogc @property T length();

      Returns the actual length of this quaternion

    • Declaration

      const pure @nogc @property T sq_length();

      Returns the actual squared length of this quaternion

    • Declaration

      const pure @nogc bool opEquals()(auto ref const Quaternion rhs);

      Define Equality

    • Declaration

      const pure @nogc bool approxEqual()(auto ref const Quaternion rhs, T maxRelDiff = 0.01, T maxAbsDiff = 1e-05);

      Approximated equality with controlable precision

    • Declaration

      const pure @nogc Quaternion opUnary(string op)() if (op == "+" || op == "-");

      Define unary operators + and -

    • Declaration

      const pure @nogc Quaternion opBinary(string op)(auto ref const Quaternion rhs) if (op == "+" || op == "-");

      Define binary operator + and -

    • Declaration

      const pure @nogc Quaternion opBinary(string op)(in T rhs) if (op == "*");

      Define Scalar multiplication

    • Declaration

      const pure @nogc Quaternion opBinary(string op)(auto ref const Quaternion rhs) if (op == "*");

      Defines Hamilton product for Quaternions

      Parameters

      Quaternion rhs

      Quaternion at rigth of operation

      Return: Quaternion result of hamilton product of this and rhs (this rhs)

    • Declaration

      const pure @nogc Quaternion conj();

      Obtain conjugate of a Quaternion

    • Declaration

      const pure @nogc @property bool isUnit();

      It's a unitary Quaternion (length == 1)

    • Declaration

      pure @nogc void normalize();

      Normalize this Quaternion

    • Declaration

      const pure V rotate(V)(auto ref const V v) if (isVector!V && (V.dim >= 3));

      Apply a 3d rotation Quaternion over a 3d/4d Vector

    • Declaration

      const pure @nogc Vector!(T, 3) toAxisAngle(out T angle);

      Calc the Axis and angle of rotation of this Quaternion

      Parameters

      T angle

      Set to angle of rotation

      Return Value

      Axis of rotation vector

    • Declaration

      const pure @nogc Vector!(T, 3) toEuler();

      Returns a Vector with euler's angles

      Return Value

      Vector with Euler angles of rotation in radians

      TODO: Improve using code from here to avoid requiring pre-normalize the quaternion http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/

    • Declaration

      const pure @nogc Tout opCast(Tout)() if (isQuaternion!Tout);

      Casting for convert between Quaternions

    • Declaration

      const pure @nogc Tout opCast(Tout)() if (isMatrix!Tout && (Tout.dim >= 3));

      Casting to rotation Matrix

    • Declaration

      string toString();

      Returns a string representation of this Quaternion

  • Declaration

    immutable bool isQuaternion(T);

    Say if a thing it's a Quaternion