VTK  9.4.20250206
vtkQuaternion.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
24#ifndef vtkQuaternion_h
25#define vtkQuaternion_h
26
27#include "vtkTuple.h"
28
29VTK_ABI_NAMESPACE_BEGIN
30template <typename T>
31class vtkQuaternion : public vtkTuple<T, 4>
32{
33public:
38
42 explicit vtkQuaternion(const T& scalar)
43 : vtkTuple<T, 4>(scalar)
44 {
45 }
46
52 explicit vtkQuaternion(const T* init)
53 : vtkTuple<T, 4>(init)
54 {
55 }
56
60 vtkQuaternion(const T& w, const T& x, const T& y, const T& z);
61
65 T SquaredNorm() const;
66
70 T Norm() const;
71
75 void ToIdentity();
76
82
88
93
97 void Conjugate();
98
103
109 void Invert();
110
115
121 void ToUnitLog();
122
129
135 void ToUnitExp();
136
143
149
155
157
160 void Set(const T& w, const T& x, const T& y, const T& z);
161 void Set(T quat[4]);
162 void Get(T quat[4]) const;
164
166
169 void SetW(const T& w);
170 const T& GetW() const;
172
174
177 void SetX(const T& x);
178 const T& GetX() const;
180
182
185 void SetY(const T& y);
186 const T& GetY() const;
188
190
193 void SetZ(const T& z);
194 const T& GetZ() const;
196
198
202 T GetRotationAngleAndAxis(T axis[3]) const;
203 void SetRotationAngleAndAxis(T angle, T axis[3]);
204 void SetRotationAngleAndAxis(const T& angle, const T& x, const T& y, const T& z);
206
210 template <typename CastTo>
212
218 void ToMatrix3x3(T A[3][3]) const;
219
226 void FromMatrix3x3(const T A[3][3]);
227
235
242
247
252
257
261 vtkQuaternion<T> operator*(const T& scalar) const;
262
266 void operator*=(const T& scalar) const;
267
272
276 vtkQuaternion<T> operator/(const T& scalar) const;
277
279
282 void operator/=(const T& scalar);
284};
285
290#define vtkQuaternionIdentity(quaternionType, type) \
291 quaternionType Identity() const \
292 { \
293 return quaternionType(vtkQuaternion<type>::Identity().GetData()); \
294 }
295#define vtkQuaternionNormalized(quaternionType, type) \
296 quaternionType Normalized() const \
297 { \
298 return quaternionType(vtkQuaternion<type>::Normalized().GetData()); \
299 }
300#define vtkQuaternionConjugated(quaternionType, type) \
301 quaternionType Conjugated() const \
302 { \
303 return quaternionType(vtkQuaternion<type>::Conjugated().GetData()); \
304 }
305#define vtkQuaternionInverse(quaternionType, type) \
306 quaternionType Inverse() const \
307 { \
308 return quaternionType(vtkQuaternion<type>::Inverse().GetData()); \
309 }
310#define vtkQuaternionUnitLog(quaternionType, type) \
311 quaternionType UnitLog() const \
312 { \
313 return quaternionType(vtkQuaternion<type>::UnitLog().GetData()); \
314 }
315#define vtkQuaternionUnitExp(quaternionType, type) \
316 quaternionType UnitExp() const \
317 { \
318 return quaternionType(vtkQuaternion<type>::UnitExp().GetData()); \
319 }
320#define vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
321 quaternionType NormalizedWithAngleInDegrees() const \
322 { \
323 return quaternionType(vtkQuaternion<type>::NormalizedWithAngleInDegrees().GetData()); \
324 }
325#define vtkQuaternionSlerp(quaternionType, type) \
326 quaternionType Slerp(type t, const quaternionType& q) const \
327 { \
328 return quaternionType(vtkQuaternion<type>::Slerp(t, q).GetData()); \
329 }
330#define vtkQuaternionInnerPoint(quaternionType, type) \
331 quaternionType InnerPoint(const quaternionType& q1, const quaternionType& q2) const \
332 { \
333 return quaternionType(vtkQuaternion<type>::InnerPoint(q1, q2).GetData()); \
334 }
335#define vtkQuaternionOperatorPlus(quaternionType, type) \
336 inline quaternionType operator+(const quaternionType& q) const \
337 { \
338 return quaternionType( \
339 (static_cast<vtkQuaternion<type>>(*this) + static_cast<vtkQuaternion<type>>(q)).GetData()); \
340 }
341#define vtkQuaternionOperatorMinus(quaternionType, type) \
342 inline quaternionType operator-(const quaternionType& q) const \
343 { \
344 return quaternionType( \
345 (static_cast<vtkQuaternion<type>>(*this) - static_cast<vtkQuaternion<type>>(q)).GetData()); \
346 }
347#define vtkQuaternionOperatorMultiply(quaternionType, type) \
348 inline quaternionType operator*(const quaternionType& q) const \
349 { \
350 return quaternionType( \
351 (static_cast<vtkQuaternion<type>>(*this) * static_cast<vtkQuaternion<type>>(q)).GetData()); \
352 }
353#define vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
354 inline quaternionType operator*(const type& scalar) const \
355 { \
356 return quaternionType((static_cast<vtkQuaternion<type>>(*this) * scalar).GetData()); \
357 }
358#define vtkQuaternionOperatorDivide(quaternionType, type) \
359 inline quaternionType operator/(const quaternionType& q) const \
360 { \
361 return quaternionType( \
362 (static_cast<vtkQuaternion<type>>(*this) / static_cast<vtkQuaternion<type>>(q)).GetData()); \
363 }
364#define vtkQuaternionOperatorDivideScalar(quaternionType, type) \
365 inline quaternionType operator/(const type& scalar) const \
366 { \
367 return quaternionType((static_cast<vtkQuaternion<type>>(*this) / scalar).GetData()); \
368 }
369
370#define vtkQuaternionOperatorMacro(quaternionType, type) \
371 vtkQuaternionIdentity(quaternionType, type); \
372 vtkQuaternionNormalized(quaternionType, type); \
373 vtkQuaternionConjugated(quaternionType, type); \
374 vtkQuaternionInverse(quaternionType, type); \
375 vtkQuaternionUnitLog(quaternionType, type); \
376 vtkQuaternionUnitExp(quaternionType, type); \
377 vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type); \
378 vtkQuaternionSlerp(quaternionType, type); \
379 vtkQuaternionInnerPoint(quaternionType, type); \
380 vtkQuaternionOperatorPlus(quaternionType, type); \
381 vtkQuaternionOperatorMinus(quaternionType, type); \
382 vtkQuaternionOperatorMultiply(quaternionType, type); \
383 vtkQuaternionOperatorMultiplyScalar(quaternionType, type); \
384 vtkQuaternionOperatorDivide(quaternionType, type); \
385 vtkQuaternionOperatorDivideScalar(quaternionType, type)
386
387// .NAME vtkQuaternionf - Float quaternion type.
388//
389// .SECTION Description
390// This class is uses vtkQuaternion with float type data.
391// For further description, see the templated class vtkQuaternion.
392// @sa vtkQuaterniond vtkQuaternion
393class vtkQuaternionf : public vtkQuaternion<float>
394{
395public:
396 vtkQuaternionf() = default;
397 explicit vtkQuaternionf(float w, float x, float y, float z)
398 : vtkQuaternion<float>(w, x, y, z)
399 {
400 }
401 explicit vtkQuaternionf(float scalar)
402 : vtkQuaternion<float>(scalar)
403 {
404 }
405 explicit vtkQuaternionf(const float* init)
406 : vtkQuaternion<float>(init)
407 {
408 }
410};
411
412// .NAME vtkQuaterniond - Double quaternion type.
413//
414// .SECTION Description
415// This class is uses vtkQuaternion with double type data.
416// For further description, seethe templated class vtkQuaternion.
417// @sa vtkQuaternionf vtkQuaternion
418class vtkQuaterniond : public vtkQuaternion<double>
419{
420public:
421 vtkQuaterniond() = default;
422 explicit vtkQuaterniond(double w, double x, double y, double z)
423 : vtkQuaternion<double>(w, x, y, z)
424 {
425 }
426 explicit vtkQuaterniond(double scalar)
427 : vtkQuaternion<double>(scalar)
428 {
429 }
430 explicit vtkQuaterniond(const double* init)
431 : vtkQuaternion<double>(init)
432 {
433 }
435};
436
437VTK_ABI_NAMESPACE_END
438#include "vtkQuaternion.txx"
439
440#endif // vtkQuaternion_h
441// VTK-HeaderTest-Exclude: vtkQuaternion.h
templated base type for storage of quaternions.
static vtkQuaternion< T > Identity()
Return the identity quaternion.
void SetRotationAngleAndAxis(T angle, T axis[3])
Set/Get the angle (in radians) and the axis corresponding to the axis-angle rotation of this quaterni...
vtkQuaternion(const T &scalar)
Initialize all of the quaternion's elements with the supplied scalar.
void SetX(const T &x)
Set/Get the x component of the quaternion, i.e.
void Set(T quat[4])
Set/Get the w, x, y and z components of the quaternion.
void SetZ(const T &z)
Set/Get the y component of the quaternion, i.e.
vtkQuaternion< T > operator+(const vtkQuaternion< T > &q) const
Performs addition of quaternion of the same basic type.
vtkQuaternion< T > Conjugated() const
Return the conjugate form of this quaternion.
void ToUnitExp()
Convert this quaternion to a unit exponential quaternion.
void SetRotationAngleAndAxis(const T &angle, const T &x, const T &y, const T &z)
Set/Get the angle (in radians) and the axis corresponding to the axis-angle rotation of this quaterni...
void SetW(const T &w)
Set/Get the w component of the quaternion, i.e.
const T & GetX() const
Set/Get the x component of the quaternion, i.e.
T Norm() const
Get the norm of the quaternion, i.e.
vtkQuaternion< T > UnitLog() const
Return the unit log version of this quaternion.
void SetY(const T &y)
Set/Get the y component of the quaternion, i.e.
const T & GetZ() const
Set/Get the y component of the quaternion, i.e.
void operator/=(const T &scalar)
Performs in place division of the quaternions by a scalar value.
void ToMatrix3x3(T A[3][3]) const
Convert a quaternion to a 3x3 rotation matrix.
vtkQuaternion(const T *init)
Initialize the quaternion's elements with the elements of the supplied array.
vtkQuaternion< T > Slerp(T t, const vtkQuaternion< T > &q) const
Interpolate quaternions using spherical linear interpolation between this quaternion and q1 to produc...
vtkQuaternion< CastTo > Cast() const
Cast the quaternion to the specified type and return the result.
void Invert()
Invert the quaternion in place.
void Get(T quat[4]) const
Set/Get the w, x, y and z components of the quaternion.
vtkQuaternion< T > operator/(const T &scalar) const
Performs division of the quaternions by a scalar value.
void Set(const T &w, const T &x, const T &y, const T &z)
Set/Get the w, x, y and z components of the quaternion.
void operator*=(const T &scalar) const
Performs in place multiplication of the quaternions by a scalar value.
vtkQuaternion(const T &w, const T &x, const T &y, const T &z)
Initialize the quaternion element explicitly.
vtkQuaternion< T > operator-(const vtkQuaternion< T > &q) const
Performs subtraction of quaternions of the same basic type.
T SquaredNorm() const
Get the squared norm of the quaternion.
T Normalize()
Normalize the quaternion in place.
vtkQuaternion< T > operator/(const vtkQuaternion< T > &q) const
Performs division of quaternions of the same type.
vtkQuaternion< T > UnitExp() const
Return the unit exponential version of this quaternion.
T GetRotationAngleAndAxis(T axis[3]) const
Set/Get the angle (in radians) and the axis corresponding to the axis-angle rotation of this quaterni...
void ToUnitLog()
Convert this quaternion to a unit log quaternion.
void FromMatrix3x3(const T A[3][3])
Convert a 3x3 matrix into a quaternion.
vtkQuaternion< T > operator*(const T &scalar) const
Performs multiplication of the quaternions by a scalar value.
void Conjugate()
Conjugate the quaternion in place.
vtkQuaternion< T > InnerPoint(const vtkQuaternion< T > &q1, const vtkQuaternion< T > &q2) const
Interpolates between quaternions, using spherical quadrangle interpolation.
vtkQuaternion< T > operator*(const vtkQuaternion< T > &q) const
Performs multiplication of quaternion of the same basic type.
void ToIdentity()
Set the quaternion to identity in place.
vtkQuaternion< T > Inverse() const
Return the inverted form of this quaternion.
void NormalizeWithAngleInDegrees()
Normalize a quaternion in place and transform it to so its angle is in degrees and its axis normalize...
vtkQuaternion()
Default constructor.
vtkQuaternion< T > Normalized() const
Return the normalized form of this quaternion.
vtkQuaternion< T > NormalizedWithAngleInDegrees() const
Returns a quaternion normalized and transformed so its angle is in degrees and its axis normalized.
const T & GetY() const
Set/Get the y component of the quaternion, i.e.
const T & GetW() const
Set/Get the w component of the quaternion, i.e.
vtkQuaterniond(double w, double x, double y, double z)
vtkQuaternionOperatorMacro(vtkQuaterniond, double)
vtkQuaterniond(const double *init)
vtkQuaterniond()=default
vtkQuaterniond(double scalar)
vtkQuaternionf(float scalar)
vtkQuaternionf(const float *init)
vtkQuaternionOperatorMacro(vtkQuaternionf, float)
vtkQuaternionf()=default
vtkQuaternionf(float w, float x, float y, float z)
templated base type for containers of constant size.
Definition vtkTuple.h:27