2009-12-07 16:03:53 +01:00
|
|
|
#ifndef _OWLPS_POSITIONING_POINT3D_HH_
|
|
|
|
#define _OWLPS_POSITIONING_POINT3D_HH_
|
|
|
|
|
2010-01-06 01:18:14 +01:00
|
|
|
#include <ostream>
|
2009-12-07 16:03:53 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Represents a point of the 3-D space
|
2009-12-07 16:03:53 +01:00
|
|
|
class Point3D
|
|
|
|
{
|
|
|
|
protected:
|
2010-01-16 12:23:07 +01:00
|
|
|
float x ; ///< X horizontal coordinate (abscissa)
|
|
|
|
float y ; ///< Y horizontal coordinate (ordinate)
|
|
|
|
float z ; ///< Vertical coordinate
|
2009-12-07 16:03:53 +01:00
|
|
|
|
|
|
|
public:
|
2010-01-16 12:23:07 +01:00
|
|
|
/// 3 float constructor or default constructor
|
2009-12-07 16:03:53 +01:00
|
|
|
Point3D(const float &_x = 0, const float &_y = 0, const float &_z = 0) ;
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Copy constructor
|
2009-12-07 16:03:53 +01:00
|
|
|
Point3D(const Point3D &p) ;
|
2010-01-16 12:23:07 +01:00
|
|
|
/// 3-float array constructor
|
2009-12-07 16:03:53 +01:00
|
|
|
Point3D(const float c[3]) ;
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
virtual ~Point3D(void) {} ///< Destructor (do nothing)
|
|
|
|
|
|
|
|
/** @name Read accessors */
|
|
|
|
//@{
|
|
|
|
float get_x(void) const ; ///< #x read accessor
|
|
|
|
float get_y(void) const ; ///< #y read accessor
|
|
|
|
float get_z(void) const ; ///< #z read accessor
|
|
|
|
//@}
|
|
|
|
|
|
|
|
/** @name Write accessors */
|
|
|
|
//@{
|
|
|
|
void set_x(const float &_x) ; ///< #x write accessor
|
|
|
|
void set_y(const float &_y) ; ///< #y write accessor
|
|
|
|
void set_z(const float &_z) ; ///< #z write accessor
|
|
|
|
void set_coordinates(const Point3D &p) ; ///< Sets all coordinates
|
|
|
|
//@}
|
|
|
|
|
|
|
|
/** @name Distance operations */
|
|
|
|
//@{
|
|
|
|
/// Square euclidean distance to a Point3D
|
2009-12-07 16:03:53 +01:00
|
|
|
float square_distance(const Point3D &p) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Euclidean distance to a Point3D
|
2010-01-05 11:50:24 +01:00
|
|
|
float distance(const Point3D &p) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Square euclidean distance to a 3-float defined point
|
2009-12-07 16:03:53 +01:00
|
|
|
float square_distance(const float &mx,
|
|
|
|
const float &my,
|
|
|
|
const float &mz) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Euclidean distance to a 3-float defined point
|
2010-01-05 11:50:24 +01:00
|
|
|
float distance(const float &mx,
|
|
|
|
const float &my,
|
|
|
|
const float &mz) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2009-12-07 16:03:53 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/** @name Operators */
|
|
|
|
//@{
|
2010-01-13 15:29:44 +01:00
|
|
|
const Point3D& operator=(const Point3D &p) ;
|
2009-12-07 16:03:53 +01:00
|
|
|
bool operator==(const Point3D &p) const ;
|
2010-01-05 11:50:24 +01:00
|
|
|
bool operator!=(const Point3D &p) const ;
|
2009-12-07 16:03:53 +01:00
|
|
|
bool operator<(const Point3D &p) const ;
|
2010-01-05 11:50:24 +01:00
|
|
|
bool operator>(const Point3D &p) const ;
|
2009-12-07 16:03:53 +01:00
|
|
|
bool operator<=(const Point3D &p) const ;
|
2010-01-05 11:50:24 +01:00
|
|
|
bool operator>=(const Point3D &p) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2009-12-07 16:03:53 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Displays a Point3D
|
2010-01-04 17:10:42 +01:00
|
|
|
friend std::ostream& operator<<(std::ostream &os, const Point3D &p) ;
|
2009-12-07 16:03:53 +01:00
|
|
|
} ;
|
|
|
|
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Read accessors *** */
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
inline float Point3D::get_x() const
|
|
|
|
{
|
|
|
|
return x ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline float Point3D::get_y() const
|
|
|
|
{
|
|
|
|
return y ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline float Point3D::get_z() const
|
|
|
|
{
|
|
|
|
return z ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Write accessors *** */
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
inline void Point3D::set_x(const float &_x)
|
|
|
|
{
|
|
|
|
x = _x ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Point3D::set_y(const float &_y)
|
|
|
|
{
|
|
|
|
y = _y ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Point3D::set_z(const float &_z)
|
|
|
|
{
|
|
|
|
z = _z ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* Updates x, y, z by passing a Point3D.
|
2010-01-05 11:50:24 +01:00
|
|
|
* This is useful for derivated classes, and different than a direct
|
|
|
|
* call to operator=().
|
|
|
|
*/
|
|
|
|
inline void Point3D::set_coordinates(const Point3D &p)
|
|
|
|
{
|
|
|
|
this->operator=(p) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Distance operations *** */
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* Note: to compare distances, use preferably square_distance(),
|
|
|
|
* which is more efficient.
|
2010-01-05 11:50:24 +01:00
|
|
|
*/
|
|
|
|
inline float Point3D::distance(const Point3D &p) const
|
|
|
|
{
|
|
|
|
return sqrt(square_distance(p)) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* Note: to compare distances, use preferably square_distance(),
|
|
|
|
* which is more efficient.
|
2010-01-05 11:50:24 +01:00
|
|
|
*/
|
|
|
|
inline float Point3D::distance(const float &_x,
|
|
|
|
const float &_y,
|
|
|
|
const float &_z) const
|
|
|
|
{
|
|
|
|
return sqrt(square_distance(_x, _y, _z)) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Operators *** */
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
inline bool Point3D::operator!=(const Point3D &p) const
|
|
|
|
{
|
|
|
|
return !(*this == p) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Point3D::operator>(const Point3D &p) const
|
|
|
|
{
|
|
|
|
return (p < *this) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Point3D::operator<=(const Point3D &p) const
|
|
|
|
{
|
|
|
|
return (*this < p || *this == p) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Point3D::operator>=(const Point3D &p) const
|
|
|
|
{
|
|
|
|
return (p <= *this) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-07 16:03:53 +01:00
|
|
|
#endif // _OWLPS_POSITIONING_POINT3D_HH_
|