Vec class

Vec class


back to menu


This class describes vectors in 3D and allows basics operations on them.

class Vec {
public:
 Vec() : X(0), Y(0), Z(0){};default constructor
 Vec(double x, double y, double z) : X(x), Y(y), Z(z){};constructor
 Vec(const Vec& v) : X(v.X), Y(v.Y), Z(v.Z){};copy constructor
 Vec operator = (const Vec& v)affectation operator

coordinates
  double X;
  double Y;
  double Z;

  const inline double norm() const;gives the norm of the vector
  inline void operator+=(const Vec v);add a vector
  void normalize();normalize the vector (unchanged if 0)
};

const double operator|(const Vec &v1, const Vec &v2);scalar product (yes, this notation exists...)
const Vec operator*(const double &d, const Vec &v);external product
const Vec operator*(const Vec &v, const double &d);external product
const Vec operator+(const Vec &v1, const Vec &v2);add two vectors
const Vec operator-(const Vec &v1, const Vec &v2);substract v2 to v1
const Vec operator*(const Vec &v1, const Vec &v2);cross product
const Vec operator/(const Vec &v, const double &d);divide a vector by d - output an error is d = 0


back to menu