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 struct Point
00020 {
00021     float x, y, z;
00022 
00023     explicit Point(float X=.0, float Y=.0, float Z=.0) : x(X), y(Y), z(Z)  { }
00024     explicit Point(float* ptr) : x(ptr[0]), y(ptr[1]), z(ptr[2])           { }
00025 
00026     Point GetUnit() const                                         { return Point(x/GetNorm(), y/GetNorm(), z/GetNorm()); }
00027     float GetNorm() const                                         { return sqrt(x*x + y*y + z*z); }
00028 
00029     Point operator-() const                                       { return Point(-x, -y, -z); }
00030     Point& operator+=(Point const& rhs)                           { x += rhs.x, y += rhs.y, z += rhs.z; return *this; }
00031     Point& operator-=(Point const& rhs)                           { x -= rhs.x, y -= rhs.y, z -= rhs.z; return *this; }
00032     Point operator+(Point const& rhs) const                       { Point tmp(*this); tmp += rhs; return tmp; }
00033     Point operator-(Point const& rhs) const                       { Point tmp(*this); tmp -= rhs; return tmp; }
00034     Point& operator*=(float scale)                                { x *= scale, y *= scale, z *= scale; return *this; }
00035     Point operator*(float scale) const                            { Point tmp(*this); tmp *= scale; return tmp; }
00036     Point& operator/=(float scale)                                { x /= scale, y /= scale, z /= scale; return *this; }
00037     Point operator/(float scale) const                            { Point tmp(*this); tmp /= scale; return tmp; }
00038 
00039     bool operator==(Point const& rhs) const                       { return x==rhs.x && y==rhs.y && z==rhs.z; }
00040     bool operator!=(Point const& rhs) const                       { return ! ( (*this) == rhs ); }
00041 
00042 
00043     float operator*(Point const& rhs) const                       { return x * rhs.x + y * rhs.y + z * rhs.z; }
00044     Point operator^(const Point &r) const                         { return Point( (y*r.z - z*r.y), (z*r.x - x*r.z), (x*r.y - y*r.x) ); }
00045 
00046     friend ostream& operator<<(ostream& os, Point const& P)       { return os << "(" << P.x << ", " << P.y << ", " << P.z << ")"; }
00047 };
00048 
00049 typedef Point Vertex;
00050 typedef Point Vector;
00051 
00052 #endif

Generated on Mon Aug 2 16:51:15 2004 by doxygen 1.3.6