CVector3d.h
Go to the documentation of this file.
1 #ifndef i3d_CVector3d_included
2 #define i3d_CVector3d_included
3 
4 
5 // Qt includes
6 #include <QtCore/QtGlobal>
7 
8 // ACF includes
9 #include <imath/TVector.h>
10 #include <i2d/CVector2d.h>
11 #include <i3d/i3d.h>
12 
13 
14 namespace i3d
15 {
16 
17 
21 class CVector3d: public imath::TVector<3>
22 {
23 public:
25 
30  CVector3d();
34  CVector3d(double x, double y, double z);
38  CVector3d(const imath::TVector<3>& vector);
39 
43  CVector3d(const i2d::CVector2d& vector, double z = 0);
44 
48  double GetX() const;
52  void SetX(double value);
56  double GetY() const;
60  void SetY(double value);
64  double GetZ() const;
68  void SetZ(double value);
69 
75 
79  CVector3d GetCrossProduct(const imath::TVector<3>& vector) const;
80 
85  CVector3d GetNormalized(double length = 1.0) const;
86 
91 
95  bool Serialize(iser::IArchive& archive);
96 
97  CVector3d operator-() const;
98 
99  CVector3d operator+(const imath::TVector<3>& vector) const;
100  CVector3d operator-(const imath::TVector<3>& vector) const;
101  CVector3d operator*(double scalar) const;
102  CVector3d operator/(double scalar) const;
103 
104  CVector3d& operator+=(const imath::TVector<3>& vector);
105  CVector3d& operator-=(const imath::TVector<3>& vector);
106  CVector3d& operator*=(double scalar);
107  CVector3d& operator/=(double scalar);
108 };
109 
110 
111 // inline methods
112 
114 {
115 }
116 
117 
118 inline CVector3d::CVector3d(double x, double y, double z)
119 {
120  operator[](0) = x;
121  operator[](1) = y;
122  operator[](2) = z;
123 }
124 
125 
127 : BaseClass(vector)
128 {
129 }
130 
131 
132 inline CVector3d::CVector3d(const i2d::CVector2d& vector, double z)
133 {
134  operator[](0) = vector.GetX();
135  operator[](1) = vector.GetY();
136  operator[](2) = z;
137 }
138 
139 
140 inline double CVector3d::GetX() const
141 {
142  return operator[](0);
143 }
144 
145 
146 inline void CVector3d::SetX(double value)
147 {
148  operator[](0) = value;
149 }
150 
151 
152 inline double CVector3d::GetY() const
153 {
154  return operator[](1);
155 }
156 
157 
158 inline void CVector3d::SetY(double value)
159 {
160  operator[](1) = value;
161 }
162 
163 
164 inline double CVector3d::GetZ() const
165 {
166  return operator[](2);
167 }
168 
169 
170 inline void CVector3d::SetZ(double value)
171 {
172  operator[](2) = value;
173 }
174 
175 
177 {
178  return *this + vector;
179 }
180 
181 
183 {
184  return i2d::CVector2d(GetX(), GetY());
185 }
186 
187 
189 {
190  return CVector3d(-GetX(), -GetY(), -GetZ());
191 }
192 
193 
194 
196 {
197  return CVector3d(GetX() + vector[0], GetY() + vector[1], GetZ() + vector[2]);
198 }
199 
200 
201 
203 {
204  return CVector3d(GetX() - vector[0], GetY() - vector[1], GetZ() - vector[2]);
205 }
206 
207 
208 
209 inline CVector3d CVector3d::operator*(double scalar) const
210 {
211  return CVector3d(GetX() * scalar, GetY() * scalar, GetZ() * scalar);
212 }
213 
214 
215 
216 inline CVector3d CVector3d::operator/(double scalar) const
217 {
218  if (qAbs(scalar) < I_BIG_EPSILON){
219  scalar = (scalar > 0)? I_BIG_EPSILON: -I_BIG_EPSILON;
220  }
221 
222  return CVector3d(GetX() / scalar, GetY() / scalar, GetZ() / scalar);
223 }
224 
225 
226 
228 {
229  BaseClass::operator+=(vector);
230 
231  return *this;
232 }
233 
234 
235 
237 {
238  BaseClass::operator-=(vector);
239 
240  return *this;
241 }
242 
243 
244 inline CVector3d& CVector3d::operator*=(double scalar)
245 {
246  BaseClass::operator*=(scalar);
247 
248  return *this;
249 }
250 
251 
252 inline CVector3d& CVector3d::operator/=(double scalar)
253 {
254  BaseClass::operator/=(scalar);
255 
256  return *this;
257 }
258 
259 
260 } // namespace i3d
261 
262 
263 #endif // !i3d_CVector3d_included
264 
double GetZ() const
Get Y position of this vector.
Definition: CVector3d.h:164
CVector3d operator*(double scalar) const
Definition: CVector3d.h:209
double GetX() const
Get X position of this vector.
Definition: CVector3d.h:140
i2d::CVector2d GetPlaneCasted() const
Get XY part of this 3D vector.
Definition: CVector3d.h:182
CVector3d GetTranslated(const imath::TVector< 3 > &vector)
Get translated point.
Definition: CVector3d.h:176
CVector3d & operator*=(double scalar)
Definition: CVector3d.h:244
double GetY() const
Get Y position of this vector.
Definition: CVector2d.h:184
double GetY() const
Get Y position of this vector.
Definition: CVector3d.h:152
CVector3d & operator-=(const imath::TVector< 3 > &vector)
Definition: CVector3d.h:236
CVector3d()
Default constructor.
Definition: CVector3d.h:113
Definition of position or mathematical vector in 3D space.
Definition: CVector3d.h:21
bool GetNormalized(TVector< Size, double > &result, doublelength=1.0) const
Return normalized vector with the same direction and specified length.
CVector3d operator+(const imath::TVector< 3 > &vector) const
Definition: CVector3d.h:195
Represent input/output persistence archive.
Definition: IArchive.h:30
CVector3d & operator/=(double scalar)
Definition: CVector3d.h:252
CVector3d GetCrossProduct(const imath::TVector< 3 > &vector) const
Return Z coordinate of two vectors cross product.
Implementation of fixed-size mathematical vector with specified type of elements. ...
Definition: TVector.h:27
Definition of position or mathematical vector on 2D plane.
Definition: CVector2d.h:28
TVector< Size, double > & operator-=(const TVector< Size, double > &vector)
TVector< Size, double > & operator/=(doublescalar)
CVector3d operator/(double scalar) const
Definition: CVector3d.h:216
imath::TVector< 3 > BaseClass
Definition: CVector3d.h:24
CVector3d & operator+=(const imath::TVector< 3 > &vector)
Definition: CVector3d.h:227
TVector< Size, double > GetTranslated(const TVector< Size, double > &vector)
Get translated point.
static const double I_BIG_EPSILON
Definition: istd.h:26
CVector3d GetNormalized(double length=1.0) const
Return normalized vector with the same direction and specified length.
bool Serialize(iser::IArchive &archive)
Serialize this vector to specified archive.
TVector< Size, double > & operator+=(const TVector< Size, double > &vector)
void SetX(double value)
Set X position of this vector.
Definition: CVector3d.h:146
double GetX() const
Get X position of this vector.
Definition: CVector2d.h:172
void SetZ(double value)
Set Y position of this vector.
Definition: CVector3d.h:170
TVector< Size, double > & operator*=(doublescalar)
CVector3d operator-() const
Definition: CVector3d.h:188
void SetY(double value)
Set Y position of this vector.
Definition: CVector3d.h:158
const double & operator[](int i) const

© 2007-2017 Witold Gantzke and Kirill Lepskiy