CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GeQuaternion.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24
25
26#ifndef OD_GEQUATERNION_H
27#define OD_GEQUATERNION_H
29#include "Ge/GeExport.h"
30#include "Ge/GeMatrix3d.h"
31
32
33#include "TD_PackPush.h"
34
70{
71public:
72
80 : w(1.), x(0.), y(0.), z(0.)
81 {}
82
94 OdGeQuaternion(double ww, double xx, double yy, double zz)
95 : w(ww), x(xx), y(yy), z(zz)
96 {}
97
106 OdGeQuaternion& set(double ww, double xx, double yy, double zz)
107 {
108 w = ww;
109 x = xx;
110 y = yy;
111 z = zz;
112 return *this;
113 }
114
126
136 {
137 OdGeMatrix3d matrix;
138
139 matrix(0, 0) = w * w + x * x - y * y - z * z;
140 matrix(0, 1) = 2. * (x * y - w * z);
141 matrix(0, 2) = 2. * (w * y + x * z);
142
143 matrix(1, 0) = 2. * (w * z + x * y);
144 matrix(1, 1) = w * w - x * x + y * y - z * z;
145 matrix(1, 2) = 2. * (y * z - w * x);
146
147 matrix(2, 0) = 2. * (x * z - w * y);
148 matrix(2, 1) = 2. * (w * x + y * z);
149 matrix(2, 2) = w * w - x * x - y * y + z * z;
150
151 return matrix;
152 }
153
161 OdGePoint3d rotate(OdGePoint3d& sourcePoint) const
162 {
163 OdGeMatrix3d matrix = getMatrix();
164
165 return sourcePoint.transformBy(matrix);
166 }
167
176 {
177 OdGeMatrix3d matrix = getMatrix();
178
179 return vector.transformBy(matrix);
180 }
181
183 // DGN special (they use Shuster multiplication convention)
185
194 {
195 OdGeMatrix3d matrix = getMatrix().transpose();
196
197 return sourcePoint.transformBy(matrix);
198 }
199
208 {
209 OdGeMatrix3d matrix = getMatrix().transpose();
210
211 return vector.transformBy(matrix);
212 }
213
215
224 const OdGeQuaternion& quat,
225 const OdGeTol& tol = OdGeContext::gTol) const
226 {
227 return fabs(x - quat.x) <= tol.equalVector() &&
228 fabs(y - quat.y) <= tol.equalVector() &&
229 fabs(z - quat.z) <= tol.equalVector() &&
230 fabs(w - quat.w) <= tol.equalVector();
231 }
232
238 bool operator ==(const OdGeQuaternion& quat) const
239 {
240 return isEqualTo(quat);
241 }
242
248 bool operator !=(const OdGeQuaternion& quat) const
249 {
250 return !isEqualTo(quat);
251 }
252
262 double scale) const
263 {
264 return OdGeQuaternion(w * scale, x * scale, y * scale, z * scale);
265 }
266
277 OdGeQuaternion& operator *=(
278 double scale)
279 {
280 w *= scale;
281 x *= scale;
282 y *= scale;
283 z *= scale;
284 return *this;
285 }
286
295 OdGeQuaternion operator /(
296 double scale) const
297 {
298 return OdGeQuaternion(w / scale, x / scale, y / scale, z / scale);
299 }
300
309 OdGeQuaternion& operator /=(
310 double scale)
311 {
312 w /= scale;
313 x /= scale;
314 y /= scale;
315 z /= scale;
316 return *this;
317 }
318
327 OdGeQuaternion operator +(
328 const OdGeQuaternion& quat) const
329 {
330 return OdGeQuaternion(w + quat.w, x + quat.x, y + quat.y, z + quat.z);
331 }
332
341 OdGeQuaternion& operator +=(
342 const OdGeQuaternion& quat)
343 {
344 w += quat.w;
345 x += quat.x,
346 y += quat.y;
347 z += quat.z;
348 return *this;
349 }
350
359 OdGeQuaternion operator -(
360 const OdGeQuaternion& quat) const
361 {
362 return OdGeQuaternion(w - quat.w, x - quat.x, y - quat.y, z - quat.z);
363 }
364
373 OdGeQuaternion& operator -=(
374 const OdGeQuaternion& quat)
375 {
376 w -= quat.w;
377 x -= quat.x,
378 y -= quat.y;
379 z -= quat.z;
380 return *this;
381 }
382
383
391 OdGeQuaternion operator -() const { return OdGeQuaternion(-w, -x, -y, -z); }
392
396 double normSqrd() const { return w*w + x*x + y*y + z*z; }
397
401 double norm() const;
402
412
418 double dotProduct(const OdGeQuaternion& quat) const
419 {
420 return w * quat.w + x * quat.x + y * quat.y + z * quat.z;
421 }
422
431 OdGeQuaternion slerp(OdGeQuaternion& q, double t, bool bUseShortestPath);
432
436 double w;
440 double x;
444 double y;
448 double z;
449
454
455};
456
457#include "TD_PackPop.h"
458
459
460#endif // OD_GEQUATERNION_H
AECBASE_API OdGePoint3d operator*(const AECECS &matrix, const OdGePoint3d &point)
tol
Definition: DimVarDefs.h:2287
scale
Definition: DimVarDefs.h:1684
#define GE_TOOLKIT_EXPORT
Definition: GeExport.h:49
#define GE_STATIC_EXPORT
Definition: GeExport.h:52
bool operator!=(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:403
bool operator==(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:397
OdGeMatrix3d transpose() const
OdGePoint3d & transformBy(const OdGeMatrix3d &xfm)
OdGeQuaternion slerp(OdGeQuaternion &q, double t, bool bUseShortestPath)
double normSqrd() const
Definition: GeQuaternion.h:396
OdGeMatrix3d getMatrix() const
Definition: GeQuaternion.h:135
OdGePoint3d rotateOpposite(OdGePoint3d &sourcePoint) const
Definition: GeQuaternion.h:193
double norm() const
double dotProduct(const OdGeQuaternion &quat) const
Definition: GeQuaternion.h:418
OdGeVector3d rotateOpposite(OdGeVector3d &vector) const
Definition: GeQuaternion.h:207
OdGeQuaternion & set(const OdGeMatrix3d &matrix)
OdGeQuaternion(double ww, double xx, double yy, double zz)
Definition: GeQuaternion.h:94
OdGePoint3d rotate(OdGePoint3d &sourcePoint) const
Definition: GeQuaternion.h:161
bool isEqualTo(const OdGeQuaternion &quat, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeQuaternion.h:223
OdGeQuaternion & normalize(const OdGeTol &tol=OdGeContext::gTol)
OdGeVector3d rotate(OdGeVector3d &vector) const
Definition: GeQuaternion.h:175
OdGeQuaternion & set(double ww, double xx, double yy, double zz)
Definition: GeQuaternion.h:106
static GE_STATIC_EXPORT const OdGeQuaternion kIdentity
Definition: GeQuaternion.h:453
Definition: GeTol.h:49
OdGeVector3d & transformBy(const OdGeMatrix3d &xfm)
GLfloat GLfloat GLfloat z
Definition: gles2_ext.h:318
GLfloat GLfloat GLfloat GLfloat w
Definition: gles2_ext.h:320
GLfloat x
Definition: gles2_ext.h:314
GLfloat GLfloat y
Definition: gles2_ext.h:316
static GE_STATIC_EXPORT OdGeTol gTol
Definition: GeGbl.h:65