00001
00024 #ifndef _HUGIN_MATH_VECTOR3_H_
00025 #define _HUGIN_MATH_VECTOR3_H_
00026
00027 #include <hugin_shared.h>
00028 #include <iostream>
00029
00030
00031
00032 #define EPSILON 0.0000001
00033
00034
00043 class IMPEX Vector3
00044 {
00045 public:
00047 double x, y, z;
00048
00049 public:
00050
00052 Vector3(): x(0), y(0), z(0) {}
00053
00055 Vector3(double a, double b, double c): x(a), y(b), z(c) {}
00056
00058 Vector3(const Vector3& v) { x = v.x; y = v.y; z = v.z; }
00059
00061 inline Vector3& operator= (const Vector3& v)
00062 {
00063 x = v.x;
00064 y = v.y;
00065 z = v.z;
00066 return *this;
00067 }
00068
00070 void Set(double a, double b, double c);
00071
00073 inline bool operator== (const Vector3& v) const
00074 {
00075 return (v.x==x && v.y==y && v.z==z);
00076 }
00077
00079 inline bool operator!= (const Vector3& v ) const
00080 {
00081 return !(v == *this);
00082 }
00083
00085 bool IsZero() const;
00086
00088 bool IsNearlyZero() const;
00089
00091 bool IsNearlyEqual(const Vector3& v) const;
00092
00094 friend Vector3 operator*( double Scale, const Vector3 & v )
00095 {
00096 return Vector3( v.x * Scale, v.y * Scale, v.z * Scale );
00097 }
00098
00100 inline Vector3 operator+( const Vector3& v ) const
00101 {
00102 return Vector3( x + v.x, y + v.y, z + v.z );
00103 }
00104
00106 inline Vector3 operator-( const Vector3& v ) const
00107 {
00108 return Vector3( x - v.x, y - v.y, z - v.z );
00109 }
00110
00112 inline Vector3 operator*( double Scale ) const
00113 {
00114 return Vector3( x * Scale, y * Scale, z * Scale );
00115 }
00116
00118 Vector3 operator/( double Scale ) const;
00119
00121 inline Vector3 operator-() const
00122 {
00123 return Vector3( -x, -y, -z );
00124 }
00125
00127 inline Vector3 operator+=( const Vector3& v )
00128 {
00129 x += v.x;
00130 y += v.y;
00131 z += v.z;
00132 return *this;
00133 }
00134
00136 inline Vector3 operator-=( const Vector3& v )
00137 {
00138 x -= v.x;
00139 y -= v.y;
00140 z -= v.z;
00141 return *this;
00142 }
00143
00145 inline Vector3 operator*=( double Scale )
00146 {
00147 x *= Scale;
00148 y *= Scale;
00149 z *= Scale;
00150 return *this;
00151 }
00152
00154 Vector3 operator/=( double Scale );
00155
00157 double Norm() const;
00158
00160 double NormSquared() const;
00161
00163 inline Vector3 Cross( const Vector3& v ) const
00164 {
00165 return Vector3( v.z*y - v.y*z, v.x*z - v.z*x, v.y*x - v.x*y);
00166 }
00167
00169 inline double Dot( const Vector3& v ) const
00170 {
00171 return x*v.x + y*v.y + z*v.z;
00172 }
00173
00175 bool Normalize();
00176
00178 Vector3 GetNormalized() const;
00179 };
00180
00181
00183 inline std::ostream & operator<<(std::ostream & s, const Vector3 & v)
00184 {
00185 s << "[ " << v.x << ", " << v.y << ", " << v.z << " ]";
00186 return s;
00187 }
00188
00189 #endif // _H