ACF $AcfVersion:0$
CVector3d.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
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
14namespace i3d
15{
16
17
73class CVector3d: public imath::TVector<3>
74{
75public:
77
95 CVector3d();
96
109 CVector3d(double x, double y, double z);
110
116 CVector3d(const imath::TVector<3>& vector);
117
133 CVector3d(const i2d::CVector2d& vector, double z = 0);
134
142 double GetX() const;
143
151 void SetX(double value);
152
160 double GetY() const;
161
169 void SetY(double value);
170
178 double GetZ() const;
179
187 void SetZ(double value);
188
199
230
235 CVector3d GetNormalized(double length = 1.0) const;
236
241
245 bool Serialize(iser::IArchive& archive);
246
247 CVector3d operator-() const;
248
249 CVector3d operator+(const imath::TVector<3>& vector) const;
250 CVector3d operator-(const imath::TVector<3>& vector) const;
251 CVector3d operator*(double scalar) const;
252 CVector3d operator/(double scalar) const;
253
254 CVector3d& operator+=(const imath::TVector<3>& vector);
255 CVector3d& operator-=(const imath::TVector<3>& vector);
256 CVector3d& operator*=(double scalar);
257 CVector3d& operator/=(double scalar);
258};
259
260
261// inline methods
262
264{
265}
266
267
268inline CVector3d::CVector3d(double x, double y, double z)
269{
270 operator[](0) = x;
271 operator[](1) = y;
272 operator[](2) = z;
273}
274
275
277: BaseClass(vector)
278{
279}
280
281
282inline CVector3d::CVector3d(const i2d::CVector2d& vector, double z)
283{
284 operator[](0) = vector.GetX();
285 operator[](1) = vector.GetY();
286 operator[](2) = z;
287}
288
289
290inline double CVector3d::GetX() const
291{
292 return operator[](0);
293}
294
295
296inline void CVector3d::SetX(double value)
297{
298 operator[](0) = value;
299}
300
301
302inline double CVector3d::GetY() const
303{
304 return operator[](1);
305}
306
307
308inline void CVector3d::SetY(double value)
309{
310 operator[](1) = value;
311}
312
313
314inline double CVector3d::GetZ() const
315{
316 return operator[](2);
317}
318
319
320inline void CVector3d::SetZ(double value)
321{
322 operator[](2) = value;
323}
324
325
327{
328 return *this + vector;
329}
330
331
333{
334 return i2d::CVector2d(GetX(), GetY());
335}
336
337
339{
340 return CVector3d(-GetX(), -GetY(), -GetZ());
341}
342
343
344
346{
347 return CVector3d(GetX() + vector[0], GetY() + vector[1], GetZ() + vector[2]);
348}
349
350
351
353{
354 return CVector3d(GetX() - vector[0], GetY() - vector[1], GetZ() - vector[2]);
355}
356
357
358
359inline CVector3d CVector3d::operator*(double scalar) const
360{
361 return CVector3d(GetX() * scalar, GetY() * scalar, GetZ() * scalar);
362}
363
364
365
366inline CVector3d CVector3d::operator/(double scalar) const
367{
368 if (qAbs(scalar) < I_BIG_EPSILON){
369 scalar = (scalar > 0)? I_BIG_EPSILON: -I_BIG_EPSILON;
370 }
371
372 return CVector3d(GetX() / scalar, GetY() / scalar, GetZ() / scalar);
373}
374
375
376
378{
379 BaseClass::operator+=(vector);
380
381 return *this;
382}
383
384
385
387{
388 BaseClass::operator-=(vector);
389
390 return *this;
391}
392
393
394inline CVector3d& CVector3d::operator*=(double scalar)
395{
396 BaseClass::operator*=(scalar);
397
398 return *this;
399}
400
401
402inline CVector3d& CVector3d::operator/=(double scalar)
403{
404 BaseClass::operator/=(scalar);
405
406 return *this;
407}
408
409
410} // namespace i3d
411
412
413
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
Represents a position or mathematical vector in 3D space with double precision.
Definition CVector3d.h:74
void SetZ(double value)
Sets the Z coordinate of the vector.
Definition CVector3d.h:320
CVector3d operator*(double scalar) const
Definition CVector3d.h:359
imath::TVector< 3 > BaseClass
Definition CVector3d.h:76
CVector3d()
Default constructor creating an uninitialized vector.
Definition CVector3d.h:263
bool Serialize(iser::IArchive &archive)
Serialize this vector to specified archive.
CVector3d & operator/=(double scalar)
Definition CVector3d.h:402
double GetX() const
Gets the X coordinate of the vector.
Definition CVector3d.h:290
void SetX(double value)
Sets the X coordinate of the vector.
Definition CVector3d.h:296
double GetY() const
Gets the Y coordinate of the vector.
Definition CVector3d.h:302
CVector3d & operator*=(double scalar)
Definition CVector3d.h:394
CVector3d GetTranslated(const imath::TVector< 3 > &vector)
Returns a new vector translated by the given offset.
Definition CVector3d.h:326
double GetZ() const
Gets the Z coordinate of the vector.
Definition CVector3d.h:314
i2d::CVector2d GetPlaneCasted() const
Get XY part of this 3D vector.
Definition CVector3d.h:332
CVector3d & operator-=(const imath::TVector< 3 > &vector)
Definition CVector3d.h:386
CVector3d operator+(const imath::TVector< 3 > &vector) const
Definition CVector3d.h:345
CVector3d operator-() const
Definition CVector3d.h:338
CVector3d & operator+=(const imath::TVector< 3 > &vector)
Definition CVector3d.h:377
CVector3d operator/(double scalar) const
Definition CVector3d.h:366
void SetY(double value)
Sets the Y coordinate of the vector.
Definition CVector3d.h:308
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
Calculates the cross product of this vector with another vector.
Implementation of fixed-size mathematical vector with specified type of elements.
Definition TVector.h:95
const double & operator[](int i) const
Definition TVector.h:882
TVector< Size, double > & operator+=(const TVector< Size, double > &vector)
Definition TVector.h:773
TVector< Size, double > & operator/=(double scalar)
Definition TVector.h:806
TVector< Size, double > & operator-=(const TVector< Size, double > &vector)
Definition TVector.h:784
TVector< Size, double > & operator*=(double scalar)
Definition TVector.h:795
TVector< Size, double > GetTranslated(const TVector< Size, double > &vector)
Returns a new vector that is the translation of this vector.
Definition TVector.h:617
bool GetNormalized(TVector< Size, double > &result, double length=1.0) const
Returns a normalized copy of this vector with specified length.
Definition TVector.h:960
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
static const double I_BIG_EPSILON
Definition istd.h:26
Contains the 3D objects.
Definition CAffine3d.h:12