Main Page | File List

Point.h

Go to the documentation of this file.
00001 /**
00002  *\file         Point.h
00003  *
00004  *\brief        Point is a float triple, also type defined as Vertex and Vector.
00005  *
00006  *\author       Xianming Chen
00007  *
00008  *\date         11 Jul 2004\n
00009  */
00010 
00011 
00012 #ifndef _POINT_H
00013 #define _POINT_H
00014 
00015 #include <iostream>
00016 
00017 using namespace std;
00018 
00019 namespace columbia
00020 {
00021   struct Point 
00022   {
00023       Point(float X=.0, float Y=.0, float Z=.0) : x(X), y(Y), z(Z) { }
00024       float x, y, z;
00025 
00026       Point GetUnit() const { return Point(x/GetNorm(), y/GetNorm(), z/GetNorm()); }
00027       
00028 
00029       float operator*(Point const& rhs) const 
00030       {
00031         float dot_pro = 0.0;
00032         dot_pro += x * rhs.x;
00033         dot_pro += y * rhs.y;
00034         dot_pro += z * rhs.z;
00035         return dot_pro;
00036       }
00037       float GetNorm() const 
00038       { 
00039         float nm = 0.0;
00040         nm += x * x;
00041         nm += y * y;
00042         nm += z * z;
00043         return sqrt(nm);
00044       }
00045 
00046       Point& operator+=(Point const& rhs) { x += rhs.x, y += rhs.y, z += rhs.z; return *this; }
00047       Point& operator-=(Point const& rhs) { x -= rhs.x, y -= rhs.y, z -= rhs.z; return *this; }
00048       Point operator-() { return Point(-x, -y, -z); }
00049       Point operator+(Point const& rhs) const { Point tmp(*this); tmp += rhs; return tmp; }
00050       Point operator-(Point const& rhs) const { Point tmp(*this); tmp -= rhs; return tmp; }
00051       Point& operator*=(float scale) { x *= scale, y *= scale, z *= scale; return *this; }
00052       Point operator*(float scale) const { Point tmp(*this); tmp *= scale; return tmp; }
00053       Point& operator/=(float scale) { x /= scale, y /= scale, z /= scale; return *this; }
00054       Point operator/(float scale) const { Point tmp(*this); tmp /= scale; return tmp; }
00055   };
00056   
00057   typedef Point Vertex;
00058   typedef Point Vector;
00059 
00060   inline ostream& operator<<(ostream& os, Point const& P)
00061   {
00062     return os << P.x << ", " << P.y << ", " << P.z;
00063   }
00064   
00065 }//end namespace xchen
00066 
00067 
00068 #endif

Generated on Sun Jul 18 20:32:35 2004 by doxygen 1.3.6