Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vector3.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
24 #ifndef _HUGIN_MATH_VECTOR3_H_
25 #define _HUGIN_MATH_VECTOR3_H_
26 
27 #include <hugin_shared.h>
28 #include <iostream>
29 
30 
31 // small number below which we consider that it's zero
32 #define EPSILON 0.0000001
33 
34 
44 {
45 public:
47  double x, y, z;
48 
49 public:
50 
52  Vector3(): x(0), y(0), z(0) {}
53 
55  Vector3(double a, double b, double c): x(a), y(b), z(c) {}
56 
58  Vector3(const Vector3& v) { x = v.x; y = v.y; z = v.z; }
59 
61  inline Vector3& operator= (const Vector3& v)
62  {
63  x = v.x;
64  y = v.y;
65  z = v.z;
66  return *this;
67  }
68 
70  void Set(double a, double b, double c);
71 
73  inline bool operator== (const Vector3& v) const
74  {
75  return (v.x==x && v.y==y && v.z==z);
76  }
77 
79  inline bool operator!= (const Vector3& v ) const
80  {
81  return !(v == *this);
82  }
83 
85  bool IsZero() const;
86 
88  bool IsNearlyZero() const;
89 
91  bool IsNearlyEqual(const Vector3& v) const;
92 
94  friend Vector3 operator*( double Scale, const Vector3 & v )
95  {
96  return Vector3( v.x * Scale, v.y * Scale, v.z * Scale );
97  }
98 
100  inline Vector3 operator+( const Vector3& v ) const
101  {
102  return Vector3( x + v.x, y + v.y, z + v.z );
103  }
104 
106  inline Vector3 operator-( const Vector3& v ) const
107  {
108  return Vector3( x - v.x, y - v.y, z - v.z );
109  }
110 
112  inline Vector3 operator*( double Scale ) const
113  {
114  return Vector3( x * Scale, y * Scale, z * Scale );
115  }
116 
118  Vector3 operator/( double Scale ) const;
119 
121  inline Vector3 operator-() const
122  {
123  return Vector3( -x, -y, -z );
124  }
125 
127  inline Vector3 operator+=( const Vector3& v )
128  {
129  x += v.x;
130  y += v.y;
131  z += v.z;
132  return *this;
133  }
134 
136  inline Vector3 operator-=( const Vector3& v )
137  {
138  x -= v.x;
139  y -= v.y;
140  z -= v.z;
141  return *this;
142  }
143 
145  inline Vector3 operator*=( double Scale )
146  {
147  x *= Scale;
148  y *= Scale;
149  z *= Scale;
150  return *this;
151  }
152 
154  Vector3 operator/=( double Scale );
155 
157  double Norm() const;
158 
160  double NormSquared() const;
161 
163  inline Vector3 Cross( const Vector3& v ) const
164  {
165  return Vector3( v.z*y - v.y*z, v.x*z - v.z*x, v.y*x - v.x*y);
166  }
167 
169  inline double Dot( const Vector3& v ) const
170  {
171  return x*v.x + y*v.y + z*v.z;
172  }
173 
175  bool Normalize();
176 
178  Vector3 GetNormalized() const;
179 };
180 
181 
183 inline std::ostream & operator<<(std::ostream & s, const Vector3 & v)
184 {
185  s << "[ " << v.x << ", " << v.y << ", " << v.z << " ]";
186  return s;
187 }
188 
189 #endif // _H
Vector3 operator-=(const Vector3 &v)
operator -=
Definition: Vector3.h:136
double Dot(const Vector3 &v) const
dot product
Definition: Vector3.h:169
double y
Definition: Vector3.h:47
Vector3 operator*=(double Scale)
double multiply
Definition: Vector3.h:145
Vector3()
default constructor
Definition: Vector3.h:52
Vector3(const Vector3 &v)
copy contructor
Definition: Vector3.h:58
Vector3 operator+=(const Vector3 &v)
operator +=
Definition: Vector3.h:127
friend Vector3 operator*(double Scale, const Vector3 &v)
operator *
Definition: Vector3.h:94
Vector3 operator-() const
Unary minus.
Definition: Vector3.h:121
Vector3(double a, double b, double c)
constructor with initialisation
Definition: Vector3.h:55
Vector3 Cross(const Vector3 &v) const
cross product
Definition: Vector3.h:163
hugin_utils::FDiff2D operator/(const hugin_utils::FDiff2D &lhs, double val)
Definition: hugin_math.h:243
#define IMPEX
Definition: hugin_shared.h:39
Vector3 operator*(double Scale) const
operator *(double)
Definition: Vector3.h:112
std::ostream & operator<<(std::ostream &o, const hugin_utils::TDiff2D< T > &d)
Definition: hugin_math.h:238
double z
Definition: Vector3.h:47
Vector3 operator-(const Vector3 &v) const
operator -
Definition: Vector3.h:106
general : Vector3 is a class for handling 3D Vectors manipulation.
Definition: Vector3.h:43
Vector3 operator+(const Vector3 &v) const
operator +
Definition: Vector3.h:100
double x
x,y,z coordinates, 0 at the initialisation
Definition: Vector3.h:47