point.h

Go to the documentation of this file.
00001 #ifndef __UTIL__POINT_H__
00002 #define __UTIL__POINT_H__
00003 
00011 #include <config.h>
00012 #include <iostream>
00013 #include <cmath>
00014 #include <util/vector.h>
00015 
00016 namespace util {
00025   template <class T> class Point : public Vector<3,T> {
00026   public:
00028     Point( const Vector<3,T>& v ) : Vector<3,T>( v ) {}
00029     Point(const T& x = T(), const T& y = T(), const T& z = T())
00030      : Vector<3,T>( x,y,z ) { }
00032     virtual ~Point() {}
00033 
00034     Point<T> cross(const Point<T>& p) const { return this->Vector<3,T>::cross( p );}
00035     Point<T> proj(const Point<T>& p) const;
00036     T        proj_length(const Point<T>& p) const;
00037     void normalise() { this->normalize(); }
00038     void normalise(T l) { this->normalize(); ( *this ) *= l; }
00039     T distance(const Point<T>& p) const { return ( *this - p ).norm(); }
00040     T distance_sq(const Point<T>& p) const { return ( *this - p ).normsq(); }
00041     T length() const { return this->norm(); }
00042     T length_sq() const { return this->normsq(); }
00043 
00044     Point& operator+=( const Point& p ) { this->Vector<3,T>::operator+=( p ); return *this; }
00045     Point& operator-=( const Point& p ) { this->Vector<3,T>::operator-=( p ); return *this; }
00046     Point& operator*=( const T& p ) { this->Vector<3,T>::operator*=( p ); return *this; }
00047     Point& operator/=( const T& p ) { this->Vector<3,T>::operator/=( p ); return *this; }
00048     Point operator+( const Point& p ) const { return this->Vector<3,T>::operator+( p ); }
00049     Point operator-( const Point& p ) const { return this->Vector<3,T>::operator-( p ); }
00050     Point operator/( const T& p ) const { return this->Vector<3,T>::operator/( p ); }
00051     Point operator-() const { return this->Vector<3,T>::operator-(); }
00053     inline const T* c_data() const {return this->elems;}
00054   };
00055 
00061   template <class T>
00062   Point<T> operator* (const Point<T>& p, const T& s) {
00063     Point<T> r( p.Vector<3,T>::operator*( s ) );
00064     return r;
00065   }
00066 
00072   template <class T>
00073   Point<T> operator* ( const T& s, const Point<T>& p) {
00074     return p * s;
00075   }
00076 
00077 
00082   template <class T>
00083   Point<T> Point<T>::proj(const Point<T>& p) const {
00084     return ((*this * p) / p.length_sq()) * p;
00085   }
00086 
00091   template <class T>
00092   T Point<T>::proj_length(const Point<T>& p) const {
00093     return fabs(*this * p) / p.length();
00094   }
00095 
00096 }
00097 
00098 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:37:53 2013 for VVE by  doxygen 1.6.3