00001 #ifndef _POINT3D_H_
00002 #define _POINT3D_H_
00003
00004 #include "MathHelper.h"
00005 #include <sstream>
00006 #include <string>
00007
00008 namespace FemViewer {
00009
00010 template <class T>
00011 class Point3D
00012 {
00013 public:
00014 T x, y, z;
00015
00016
00017 public:
00019 Point3D(void) : x(T()), y(T()), z(T()){};
00020
00022 Point3D(T a, T b, T c):x(a), y(b), z(c){};
00023
00025 Point3D(const Point3D<T> & src) : x(src.x), y(src.y), z(src.z){};
00026
00028 Point3D<T>& operator=(const Point3D<T>& rhs)
00029 {
00030 x = rhs.x; y = rhs.y; z = rhs.z;
00031 return *this;
00032 }
00033
00034 void Set(T a, T b, T c)
00035 {
00036 x = a;
00037 y = b;
00038 z = c;
00039 };
00040
00042
00045 bool Compare(const Point3D<T> & p) const
00046 {
00047
00048 if
00049 (
00050 ( fvmath::Compare(x, p.x) )
00051 &&
00052 ( fvmath::Compare(y, p.y) )
00053 &&
00054 ( fvmath::Compare(z, p.z) )
00055 )
00056 {
00057 return true;
00058 }
00059 else
00060 return false;
00061 };
00062
00063
00064 void SetInterp(Point3D<T> a, Point3D<T> b, double interp)
00065 {
00066
00067
00068 this->x = a.x + (b.x-a.x) * interp;
00069 this->y = a.y + (b.y-a.y) * interp;
00070 this->z = a.z + (b.z-a.z) * interp;
00071
00072 };
00073
00075 static double GetInterp(Point3D<T> p1, Point3D<T> p2, Point3D<T> p0)
00076 {
00077 double l, la;
00078
00079 l = p1.Length(p2);
00080
00081 la = p1.Length(p0);
00082
00083 return la/l;
00084 };
00085
00086
00087 double Length(const Point3D<T> & p)
00088 {
00089 T vx, vy, vz;
00090 vx = p.x - x;
00091 vy = p.y - y;
00092 vz = p.z - z;
00093
00094 return sqrtf( vx*vx + vy*vy + vz*vz );
00095 };
00096
00097 std::string AsString(void) const
00098 {
00099 std::stringstream oss;
00100
00101 oss << x << ", " << y << ", " << z;
00102
00103 return oss.str();
00104 }
00105 };
00106
00107
00108 }
00109
00110 #endif
00111