/* * File: point3d.hh * Author: Jordan P. Lefebvre, lefebvre.jordan@gmail.com * * Created on August 9, 2012, 5:47 PM */ #ifndef RADIX_RADIXMATH_POINT3D_HH_ #define RADIX_RADIXMATH_POINT3D_HH_ #include #include #include #include "radixmath/constants.hh" #include "radixmath/matrix.hh" #include "radixmath/vector3d.hh" #include "radixcore/visibility.hh" namespace radix { /** * @class Point3D * @brief class object describing object in 3D space */ class RADIX_PUBLIC Point3D { public: Real x, y, z; /** * Default constructor */ Point3D(); /** * Constructor * @param a */ Point3D(const Real a); /** * Constructor * @param a * @param b * @param c */ Point3D(const Real a, const Real b, const Real c); /** * Copy Constructor * @param p */ Point3D(const Point3D &p); /** * Copy Constructor * @param p */ Point3D(const Vector3D &v) : x(v.x) , y(v.y) , z(v.z) { } /** * Destructor */ ~Point3D(); /** * Equality function * @param p * @return */ bool equals(const Point3D &p) const; inline Real &operator[](const size_t index) { switch (index) { case 0: return x; case 1: return y; case 2: return z; default: throw std::out_of_range( "Point3D range issue, index is beyond known members!"); } } /** * Operator== * @param rhs * @return true x1==x2 && y1==y2 && z1==z2, false otherwise */ bool operator==(const Point3D &rhs) const; bool operator!=(const Point3D &rhs) const; /** * Operator< * @param rhs * @return true x1 * @param rhs * @return true x1>x2 && y1>y2 && z1>z2, false otherwise */ bool operator>(const Point3D &rhs) const; /** * Operator>= * @param rhs * @return true x1>=x2 && y1>=y2 && z1>=z2, false otherwise */ bool operator>=(const Point3D &rhs) const; /** * Assignment operation * @param p * @return */ Point3D &operator=(const Point3D &p); /** * Assignment operation * @param p * @return */ Point3D &operator=(const Vector3D &v) { x = v.x; y = v.y; z = v.z; return *this; } /** * unary minus * @return */ Point3D operator-(void) const; /** * Vector joing two points * @param v * @return */ Vector3D operator-(const Point3D &p) const; /** * Addition of a vector * @param v * @return */ Point3D operator+(const Vector3D &v) const; /** * Subtraction of a vector * @param v * @return */ Point3D operator-(const Vector3D &v) const; /** * Multiplication by a Real on the right * @param a * @return */ Point3D operator*(const Real a) const; /** * Square of distance between two points * @param p * @return */ Real distance_squared(const Point3D &p) const; /** * Distance between two points * @param p * @return */ Real distance(const Point3D &p) const; /** * @brief move - moves the point along the given direction vector a distance * of distance*direction.length() * @param direction - a hopefully normalized direction vector * @param distance - the track length */ void move(const Vector3D &direction, Real distance); std::string toString() const; }; // Point3D class inline void Point3D::move(const Vector3D &direction, Real distance) { x += direction.x * distance; y += direction.y * distance; z += direction.z * distance; } /** * @function operator* * @brief multiplication by a matrix on the left */ RADIX_PUBLIC Point3D operator*(const Matrix &mat, const Point3D &p); /** * @function operator* * @brief multiplication by a Real on the left */ RADIX_PUBLIC Point3D operator*(Real a, const Point3D &p); /** * @function operation- * @brief subtraction operator */ inline Point3D Point3D::operator-(void) const { return (Point3D(-x, -y, -z)); } /** * @function operator- * @brief subtraction of a vector from a point that returns a new point */ inline Point3D Point3D::operator-(const Vector3D &v) const { return (Point3D(x - v.x, y - v.y, z - v.z)); } /* * @function operator* * @brief multiplication by a Real on the right */ inline Point3D Point3D::operator*(const Real a) const { return (Point3D(x * a, y * a, z * a)); } /** * @function operator+ * @brief addition of a vector to a point that returns a new point */ inline Point3D Point3D::operator+(const Vector3D &v) const { return (Point3D(x + v.x, y + v.y, z + v.z)); } /** * @function distance_squared * @brief the square of the distance between the two points as a member function */ inline Real Point3D::distance_squared(const Point3D &p) const { return ((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z) * (z - p.z)); } /** * @function operation* * @param a * @param p * @return */ inline RADIX_PUBLIC Point3D operator*(Real a, const Point3D &p) { return (Point3D(a * p.x, a * p.y, a * p.z)); } inline bool Point3D::equals(const Point3D &p) const { if (x == p.x && y == p.y && z == p.z) return true; return false; } inline bool Point3D::operator==(const Point3D &rhs) const { if (x == rhs.x && y == rhs.y && z == rhs.z) return true; return false; } inline bool Point3D::operator!=(const Point3D &rhs) const { if (x == rhs.x && y == rhs.y && z == rhs.z) return false; return true; } inline bool Point3D::operator<(const Point3D &rhs) const { if (x < rhs.x && y < rhs.y && z < rhs.z) return true; return false; } inline bool Point3D::operator<=(const Point3D &rhs) const { if (x <= rhs.x && y <= rhs.y && z <= rhs.z) return true; return false; } inline bool Point3D::operator>(const Point3D &rhs) const { if (x > rhs.x && y > rhs.y && z > rhs.z) return true; return false; } inline bool Point3D::operator>=(const Point3D &rhs) const { if (x >= rhs.x && y >= rhs.y && z >= rhs.z) return true; return false; } /** * Allow for printing a Point3D to stream * @param os - the stream to receive the string representation of the point * @param p - the point to be stringified * @return the stream */ RADIX_PUBLIC std::ostream &operator<<(std::ostream &os, const Point3D &p); } // namespace radix #endif /* RADIX_RADIXMATH_POINT3D_HH_*/