ICF 3.1.1.10
Technical documentation of ICF Libraries
CVector3d.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// Qt includes
10#include <QtCore/QtGlobal>
11
12// ICF includes
13#include <imath/TVector.h>
14#include <i2d/CVector2d.h>
15#include <i3d/i3d.h>
16
17
18namespace i3d
19{
20
21
25class CVector3d: public imath::TVector<3>
26{
27public:
29
34 CVector3d();
38 CVector3d(double x, double y, double z);
42 CVector3d(const imath::TVector<3>& vector);
43
47 CVector3d(const i2d::CVector2d& vector, double z = 0);
48
52 double GetX() const;
56 void SetX(double value);
60 double GetY() const;
64 void SetY(double value);
68 double GetZ() const;
72 void SetZ(double value);
73
79
84
89 CVector3d GetNormalized(double length = 1.0) const;
90
95
99 bool Serialize(iser::IArchive& archive);
100
101 CVector3d operator-() const;
102
103 CVector3d operator+(const imath::TVector<3>& vector) const;
104 CVector3d operator-(const imath::TVector<3>& vector) const;
105 CVector3d operator*(double scalar) const;
106 CVector3d operator/(double scalar) const;
107
108 CVector3d& operator+=(const imath::TVector<3>& vector);
109 CVector3d& operator-=(const imath::TVector<3>& vector);
110 CVector3d& operator*=(double scalar);
111 CVector3d& operator/=(double scalar);
112};
113
114
115// inline methods
116
118{
119}
120
121
122inline CVector3d::CVector3d(double x, double y, double z)
123{
124 operator[](0) = x;
125 operator[](1) = y;
126 operator[](2) = z;
127}
128
129
131: BaseClass(vector)
132{
133}
134
135
136inline CVector3d::CVector3d(const i2d::CVector2d& vector, double z)
137{
138 operator[](0) = vector.GetX();
139 operator[](1) = vector.GetY();
140 operator[](2) = z;
141}
142
143
144inline double CVector3d::GetX() const
145{
146 return operator[](0);
147}
148
149
150inline void CVector3d::SetX(double value)
151{
152 operator[](0) = value;
153}
154
155
156inline double CVector3d::GetY() const
157{
158 return operator[](1);
159}
160
161
162inline void CVector3d::SetY(double value)
163{
164 operator[](1) = value;
165}
166
167
168inline double CVector3d::GetZ() const
169{
170 return operator[](2);
171}
172
173
174inline void CVector3d::SetZ(double value)
175{
176 operator[](2) = value;
177}
178
179
181{
182 return *this + vector;
183}
184
185
187{
188 return i2d::CVector2d(GetX(), GetY());
189}
190
191
193{
194 return CVector3d(-GetX(), -GetY(), -GetZ());
195}
196
197
198
200{
201 return CVector3d(GetX() + vector[0], GetY() + vector[1], GetZ() + vector[2]);
202}
203
204
205
207{
208 return CVector3d(GetX() - vector[0], GetY() - vector[1], GetZ() - vector[2]);
209}
210
211
212
213inline CVector3d CVector3d::operator*(double scalar) const
214{
215 return CVector3d(GetX() * scalar, GetY() * scalar, GetZ() * scalar);
216}
217
218
219
220inline CVector3d CVector3d::operator/(double scalar) const
221{
222 if (qAbs(scalar) < I_BIG_EPSILON){
223 scalar = (scalar > 0)? I_BIG_EPSILON: -I_BIG_EPSILON;
224 }
225
226 return CVector3d(GetX() / scalar, GetY() / scalar, GetZ() / scalar);
227}
228
229
230
232{
233 BaseClass::operator+=(vector);
234
235 return *this;
236}
237
238
239
241{
242 BaseClass::operator-=(vector);
243
244 return *this;
245}
246
247
248inline CVector3d& CVector3d::operator*=(double scalar)
249{
250 BaseClass::operator*=(scalar);
251
252 return *this;
253}
254
255
256inline CVector3d& CVector3d::operator/=(double scalar)
257{
258 BaseClass::operator/=(scalar);
259
260 return *this;
261}
262
263
264} // namespace i3d
265
266
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
double GetY() const
Get Y position of this vector.
Definition CVector2d.h:184
double GetX() const
Get X position of this vector.
Definition CVector2d.h:172
Definition of position or mathematical vector in 3D space.
Definition CVector3d.h:26
void SetZ(double value)
Set Y position of this vector.
Definition CVector3d.h:174
CVector3d operator*(double scalar) const
Definition CVector3d.h:213
CVector3d()
Default constructor.
Definition CVector3d.h:117
bool Serialize(iser::IArchive &archive)
Serialize this vector to specified archive.
CVector3d & operator/=(double scalar)
Definition CVector3d.h:256
double GetX() const
Get X position of this vector.
Definition CVector3d.h:144
void SetX(double value)
Set X position of this vector.
Definition CVector3d.h:150
double GetY() const
Get Y position of this vector.
Definition CVector3d.h:156
CVector3d & operator*=(double scalar)
Definition CVector3d.h:248
CVector3d GetTranslated(const imath::TVector< 3 > &vector)
Get translated point.
Definition CVector3d.h:180
double GetZ() const
Get Y position of this vector.
Definition CVector3d.h:168
i2d::CVector2d GetPlaneCasted() const
Get XY part of this 3D vector.
Definition CVector3d.h:186
CVector3d & operator-=(const imath::TVector< 3 > &vector)
Definition CVector3d.h:240
imath::TVector< 3 > BaseClass
Definition CVector3d.h:28
CVector3d operator+(const imath::TVector< 3 > &vector) const
Definition CVector3d.h:199
CVector3d operator-() const
Definition CVector3d.h:192
CVector3d & operator+=(const imath::TVector< 3 > &vector)
Definition CVector3d.h:231
CVector3d operator/(double scalar) const
Definition CVector3d.h:220
void SetY(double value)
Set Y position of this vector.
Definition CVector3d.h:162
CVector3d GetNormalized(double length=1.0) const
Return normalized vector with the same direction and specified length.
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:32
const double & operator[](int i) const
Definition TVector.h:606
TVector< Size, double > & operator+=(const TVector< Size, double > &vector)
Definition TVector.h:497
TVector< Size, double > & operator/=(double scalar)
Definition TVector.h:530
TVector< Size, double > & operator-=(const TVector< Size, double > &vector)
Definition TVector.h:508
TVector< Size, double > & operator*=(double scalar)
Definition TVector.h:519
TVector< Size, double > GetTranslated(const TVector< Size, double > &vector)
Definition TVector.h:323
bool GetNormalized(TVector< Size, double > &result, double length=1.0) const
Definition TVector.h:684
Represent input/output persistence archive.
Definition IArchive.h:34
Contains the 3D objects.
Definition CMatrix3d.h:15

© Witold Gantzke and Kirill Lepskiy