zmath.vector

Defines a Vector of float point typefrom 2 to 4 dimension

  • Declaration

    alias Vec2r = Vector!(real, 2LU).Vector;

    Alias of a 2d Vector with reals

  • Declaration

    alias Vec3r = Vector!(real, 3LU).Vector;

    Alias of a 3d Vector with reals

  • Declaration

    alias Vec4r = Vector!(real, 4LU).Vector;

    Alias of a 4d Vector with reals

  • Declaration

    alias Vec2d = Vector!(double, 2LU).Vector;

    Alias of a 2d Vector with doubles

  • Declaration

    alias Vec3d = Vector!(double, 3LU).Vector;

    Alias of a 3d Vector with doubles

  • Declaration

    alias Vec4d = Vector!(double, 4LU).Vector;

    Alias of a 4d Vector with doubles

  • Declaration

    alias Vec2f = Vector!(float, 2LU).Vector;

    Alias of a 2d Vector with floats

  • Declaration

    alias Vec3f = Vector!(float, 3LU).Vector;

    Alias of a 3d Vector with floats

  • Declaration

    alias Vec4f = Vector!(float, 4LU).Vector;

    Alias of a 4d Vector with floats

  • Declaration

    struct Vector(T, size_t dim_) if (__traits(isFloating, T));

    N-Dimensional Vector over a FloatPoint type, where N must be 2,3 or 4

    • dim

      Declaration

      static enum size_t dim;

      Vector Dimension

    • Declaration

      T[dim] coor;

      Vector coords like Array

    • x

      Declaration

      T x;

      X coord

    • r

      Declaration

      alias r = x;

      R component

    • Declaration

      alias roll = x;

      Euler roll angle

    • Declaration

      alias bank = x;

      Euler roll angle

    • y

      Declaration

      T y;

      Y coord

    • g

      Declaration

      alias g = y;

      G component

    • Declaration

      alias pitch = y;

      Euler pith angle

    • Declaration

      alias attidue = y;

      Euler pith angle

    • z

      Declaration

      T z;

      Z coord

    • b

      Declaration

      alias b = z;

      B component

    • yaw

      Declaration

      alias yaw = z;

      Euler yaw angle

    • Declaration

      alias heading = z;

      Euler yaw angle

    • w

      Declaration

      T w;

      W coord

    • a

      Declaration

      alias a = w;

      Alpha component

    • Declaration

      static enum Vector!(T, 2) ZERO;

      Origin

    • Declaration

      static enum Vector!(T, 2) X_AXIS;

      X Axis in R2

    • Declaration

      static enum Vector!(T, 2) Y_AXIS;

      Y Axis in R2

    • Declaration

      pure @nogc this(in T x, in T y = 0, in T z = 0, in T w = 1);

      Build a new Vector from a set of initial values If no there values for z and w, will be set to 0

      Parameters

      T x

      X coord

      T y

      Y coord

      T z

      Z coord

      T w

      W coord (scale factor in 3d math)

    • Declaration

      pure this(in T[] xs);

      Build a new Vector from a array If no there values for y and z, will be set to 0. w sill beset to 1

      Parameters

      T[] xs

      Array with coords

    • Declaration

      const pure @nogc T opIndex(size_t i);

      Returns i coord of this vector

    • Declaration

      void opIndexAssign(T c, size_t i);

      Assigns a value to a i coord

    • Declaration

      const pure @nogc @property T length();

      Returns the actual length of this Vector

    • Declaration

      const pure @nogc @property T sq_length();

      Returns the actual squared length of this Vector

    • Declaration

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

      Define Equality

      Parameters

      Vector rhs

      Vector at rigth of '=='

    • Declaration

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

      Approximated equality with controlable precision

      Parameters

      Vector rhs

      Vector to compare with this vector

      T maxRelDiff

      Maximun relative difference

      T maxAbsDiff

      Maximun absolute difference

      See: std.math : approxEqual

    • Declaration

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

      Define unary operators + and -

    • Declaration

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

      Define binary operator + and -

    • Declaration

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

      Define Scalar multiplication

    • Declaration

      const pure @nogc Vector opBinaryRight(string op)(in T rhs) if (op == "*" || op == "/");

      Define Scalar multiplication

    • Declaration

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

      Define Dot Product

    • Declaration

      const pure @nogc Vector opBinary(string op)(auto ref const Vector rhs) if (op == "&" && (dim == 3));

      Define Cross Product for R3 (operation c = a & b )

    • Declaration

      const pure @nogc @property bool isUnit();

      It's a unitary vector (length == 1) Returns : True if length approxEqual to 1.0

    • Declaration

      @nogc void normalize();

      Normalize this vector

    • Declaration

      const pure @nogc @property Vector unit();

      Returns the unit vector of this vector

    • Declaration

      pure @nogc Vector projectOnTo()(auto ref const Vector a, auto ref const Vector b);

      Obtains the projection of two vectors

      Parameters

      Vector a

      Vector to project

      Vector b

      Vector where project vector a Returns : A Vector that it's projection of Vector a over Vector b

    • Declaration

      pure @nogc Vector projectOnTo()(auto ref const Vector b);

      Obtains the projection of this vector over other vector

      Parameters

      Vector b

      Vector where project this vector Returns : A Vector that it's projection of this Vector over Vector b

    • Declaration

      pure @nogc T distance()(auto ref const Vector b);

      Calculate the distance between two points pointed by this vector and other Params : b = Vector B Returns : Distance between the point pointed by this vector and other point

    • Declaration

      pure @nogc T sq_distance()(auto ref const Vector b);

      Calculate the squared distance between two points pointed by this vector and other Params : b = Vector B Returns : Squared distance between the point pointed by this vector and other point

    • Declaration

      const pure @nogc Vector rotate(real angle);

      Rotation in R2

      Parameters

      real angle

      Rotation angle Returns : A new vector that is the rotation of this vector

    • ptr

      Declaration

      pure @nogc @property T* ptr();

      Return a pointer of the internal array

    • Declaration

      const pure @nogc @property bool isOk();

      Checks that the vector not have a weird NaN value Returns : True if this vector not have a NaN value

    • Declaration

      const pure @nogc @property bool isFinite();

      Checks that the vector have finite values Returns : True if this vector have finite values (not infinite value or NaNs)

    • Declaration

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

      Casting method to convert to other vector types

    • Declaration

      const string toString();

      Returns a string representation of this vector

  • Declaration

    immutable bool isVector(T);

    Say if a thing it's a Vector