/* * File: vector3d.hh * Author: Jordan * * Created on August 9, 2012, 6:06 PM */ #ifndef RADIX_RADIXMATH_VECTOR3D_H #define RADIX_RADIXMATH_VECTOR3D_H #include #include #include "radixmath/constants.hh" #include "radixcore/visibility.hh" namespace radix { class Normal; class Point3D; class Matrix; /** * @class Vector3D */ class RADIX_PUBLIC Vector3D { public: Real x, y, z; public: /** * Constructor */ Vector3D(void); /** * Constructor * @param a */ Vector3D(Real a); /** * Constructor * @param _x * @param _y * @param _z */ Vector3D(Real _x, Real _y, Real _z); /** * Copy constructor * @param v */ Vector3D(const Vector3D &v); /** * Copy Normal Constructor * @param n */ Vector3D(const Normal &n); /** * Copy Point3D constructor * @param p */ Vector3D(const Point3D &p); /** * Destructor */ ~Vector3D(void); /** * * @param rhs * @return */ Vector3D &operator=(const Vector3D &rhs); bool operator==(const Vector3D &rhs) const; bool operator!=(const Vector3D &rhs) const; /** * Assign a {@code Normal} to a vector * @param rhs * @return */ Vector3D &operator=(const Normal &rhs); /** * Assign a {@code Point3D to a vector * @param rhs * @return */ Vector3D &operator=(const Point3D &rhs); /** * Unary minus * @return */ Vector3D operator-(void) const; Real &operator[](size_t i) { switch (i) { case 0: return x; case 1: return y; case 2: return z; } throw std::runtime_error("Unknown Vector3D member!"); } std::string toString() const; /** * Length * @return */ Real length(void) const; /** * Square of the length * @return */ Real len_squared(void) const; /** * Multiplication by a Real on the right * @param a * @return */ Vector3D operator*(const Real a) const; /** * Division by a Real * @param a * @return */ Vector3D operator/(const Real a) const; /** * Addition * @param v * @return */ Vector3D operator+(const Vector3D &v) const; /** * Compound addition * @param v * @return */ Vector3D &operator+=(const Vector3D &v); /** * Subtraction * @param v * @return */ Vector3D operator-(const Vector3D &v) const; /** * Dot Production * @param b * @return */ Real operator*(const Vector3D &b) const; /** * Cross Product * @param v * @return */ Vector3D operator^(const Vector3D &v) const; /** * Convert vector to a unit vector * @return */ void normalize(void); /** * Return a unit vector, and normalize the vector * @return */ Vector3D &normalized_vector(void); /** * @brief Obtain an orthogonal vector to this vector * If this vector is a zero vector, an exception is thrown. * The vector is not necessarily normalized * @return Vector3D - an orthogonal/perpendicular vector to this vector */ Vector3D orthogonal(void) const; /** * @brief spherical - creates a spherical Vector3D * Note x=>r, y=>theta, z=>phi * @return Vector3D where x=>r, y=>theta, z=>phi */ Vector3D spherical(void) const; Vector3D cartesian(void) const; }; /** * @function operator* * @brief multiplication by a Real on the left */ Vector3D operator*(const Real a, const Vector3D &v); /** * @function operator* * @brief multiplication by a matrix on the left */ Vector3D operator*(const Matrix &mat, const Vector3D &v); /** * Allow for printing a Vector3D to stream * @param os - the stream to receive the string representation of the vector * @param v - the vector to be stringified * @return the stream */ RADIX_PUBLIC std::ostream &operator<<(::std::ostream &os, const Vector3D &v); } // namespace radix #endif /* RADIX_RADIXMATH_VECTOR3D_H */