Loading...
Searching...
No Matches
quatd.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
8// This file is generated by a script. Do not edit directly. Edit the
9// quat.template.h file to make changes.
10
11#ifndef PXR_BASE_GF_QUATD_H
12#define PXR_BASE_GF_QUATD_H
13
16
17#include "pxr/pxr.h"
18#include "pxr/base/gf/api.h"
19#include "pxr/base/gf/declare.h"
20#include "pxr/base/gf/vec3d.h"
21#include "pxr/base/gf/traits.h"
22#include "pxr/base/tf/hash.h"
23
24#include <iosfwd>
25
26PXR_NAMESPACE_OPEN_SCOPE
27
28template <>
29struct GfIsGfQuat<class GfQuatd> { static const bool value = true; };
30
31
33double GfDot(const GfQuatd& q1, const GfQuatd& q2);
34
35
43{
44 public:
45 typedef double ScalarType;
46 typedef GfVec3d ImaginaryType;
47
50 GfQuatd() = default;
51
59 explicit GfQuatd (double realVal) : _imaginary(0), _real(realVal) {}
60
62 GfQuatd(double real, double i, double j, double k)
63 : _imaginary(i, j, k), _real(real)
64 {
65 }
66
68 GfQuatd(double real, const GfVec3d &imaginary)
69 : _imaginary(imaginary), _real(real)
70 {
71 }
72
74 GF_API
75 GfQuatd(class GfQuatf const &other);
77 GF_API
78 GfQuatd(class GfQuath const &other);
79
82 static GfQuatd GetZero() { return GfQuatd(0.0); }
83
86 static GfQuatd GetIdentity() { return GfQuatd(1.0); }
87
89 double GetReal() const { return _real; }
90
92 void SetReal(double real) { _real = real; }
93
95 const GfVec3d &GetImaginary() const { return _imaginary; }
96
98 void SetImaginary(const GfVec3d &imaginary) {
99 _imaginary = imaginary;
100 }
101
103 void SetImaginary(double i, double j, double k) {
104 _imaginary.Set(i, j, k);
105 }
106
108 double GetLength() const { return GfSqrt(_GetLengthSquared()); }
109
112 GfQuatd
114 GfQuatd ret(*this);
115 ret.Normalize(eps);
116 return ret;
117 }
118
122 GF_API
123 double Normalize(double eps = GF_MIN_VECTOR_LENGTH);
124
128 return GfQuatd(GetReal(), -GetImaginary());
129 }
130
134 return GetConjugate() / _GetLengthSquared();
135 }
136
144 GF_API
145 GfVec3d Transform(const GfVec3d& point) const;
146
148 friend inline size_t hash_value(const GfQuatd &q) {
149 return TfHash::Combine(q.GetReal(), q.GetImaginary());
150 }
151
154 return GfQuatd(-GetReal(), -GetImaginary());
155 }
156
159 bool operator==(const GfQuatd &q) const {
160 return (GetReal() == q.GetReal() &&
161 GetImaginary() == q.GetImaginary());
162 }
163
166 bool operator!=(const GfQuatd &q) const {
167 return !(*this == q);
168 }
169
171 GF_API
173
175 GfQuatd &operator *=(double s) {
176 _real *= s;
177 _imaginary *= s;
178 return *this;
179 }
180
182 GfQuatd &operator /=(double s) {
183 _real /= s;
184 _imaginary /= s;
185 return *this;
186 }
187
190 _real += q._real;
191 _imaginary += q._imaginary;
192 return *this;
193 }
194
197 _real -= q._real;
198 _imaginary -= q._imaginary;
199 return *this;
200 }
201
203 friend GfQuatd
204 operator +(const GfQuatd &q1, const GfQuatd &q2) {
205 return GfQuatd(q1) += q2;
206 }
207
209 friend GfQuatd
210 operator -(const GfQuatd &q1, const GfQuatd &q2) {
211 return GfQuatd(q1) -= q2;
212 }
213
215 friend GfQuatd
216 operator *(const GfQuatd &q1, const GfQuatd &q2) {
217 return GfQuatd(q1) *= q2;
218 }
219
221 friend GfQuatd
222 operator *(const GfQuatd &q, double s) {
223 return GfQuatd(q) *= s;
224 }
225
227 friend GfQuatd
228 operator *(double s, const GfQuatd &q) {
229 return GfQuatd(q) *= s;
230 }
231
233 friend GfQuatd
234 operator /(const GfQuatd &q, double s) {
235 return GfQuatd(q) /= s;
236 }
237
238 private:
240 GfVec3d _imaginary;
241
243 double _real;
244
246 double
247 _GetLengthSquared() const {
248 return GfDot(*this, *this);
249 }
250};
251
256GF_API GfQuatd
257GfSlerp(double alpha, const GfQuatd& q0, const GfQuatd& q1);
258
259GF_API GfQuatd
260GfSlerp(const GfQuatd& q0, const GfQuatd& q1, double alpha);
261
262inline double
263GfDot(GfQuatd const &q1, GfQuatd const &q2) {
264 return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
265 q1.GetReal()*q2.GetReal();
266}
267
270GF_API std::ostream& operator<<(std::ostream &, GfQuatd const &);
271
272PXR_NAMESPACE_CLOSE_SCOPE
273
274#endif // PXR_BASE_GF_QUATD_H
Declares Gf types.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatd.h:43
static GfQuatd GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quatd.h:86
GfQuatd & operator/=(double s)
Divide this quaternion's coefficients by s.
Definition: quatd.h:182
GfQuatd & operator+=(const GfQuatd &q)
Add quaternion q to this quaternion.
Definition: quatd.h:189
GF_API GfQuatd(class GfQuath const &other)
Implicitly convert from GfQuath.
GfQuatd(double realVal)
Initialize the real coefficient to realVal and the imaginary coefficients to zero.
Definition: quatd.h:59
GfQuatd(double real, double i, double j, double k)
Initialize the real and imaginary coefficients.
Definition: quatd.h:62
GfQuatd GetNormalized(double eps=GF_MIN_VECTOR_LENGTH) const
length of this quaternion is smaller than eps, return the identity quaternion.
Definition: quatd.h:113
GfQuatd(double real, const GfVec3d &imaginary)
Initialize the real and imaginary coefficients.
Definition: quatd.h:68
GF_API GfVec3d Transform(const GfVec3d &point) const
Transform the GfVec3d point.
GfQuatd & operator-=(const GfQuatd &q)
Component-wise unary difference operator.
Definition: quatd.h:196
friend GfQuatd operator*(const GfQuatd &q1, const GfQuatd &q2)
Returns the product of quaternions q1 and q2.
Definition: quatd.h:216
const GfVec3d & GetImaginary() const
Return the imaginary coefficient.
Definition: quatd.h:95
GF_API double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes this quaternion in place to unit length, returning the length before normalization.
GfQuatd operator-() const
Component-wise negation.
Definition: quatd.h:153
double GetReal() const
Return the real coefficient.
Definition: quatd.h:89
GfQuatd GetInverse() const
Return this quaternion's inverse, or reciprocal.
Definition: quatd.h:133
bool operator==(const GfQuatd &q) const
Component-wise quaternion equality test.
Definition: quatd.h:159
GfQuatd GetConjugate() const
Return this quaternion's conjugate, which is the quaternion with the same real coefficient and negate...
Definition: quatd.h:127
GF_API GfQuatd & operator*=(const GfQuatd &q)
Post-multiply quaternion q into this quaternion.
void SetImaginary(const GfVec3d &imaginary)
Set the imaginary coefficients.
Definition: quatd.h:98
static GfQuatd GetZero()
Return the zero quaternion, with real coefficient 0 and an imaginary coefficients all zero.
Definition: quatd.h:82
bool operator!=(const GfQuatd &q) const
Component-wise quaternion inequality test.
Definition: quatd.h:166
GF_API GfQuatd(class GfQuatf const &other)
Implicitly convert from GfQuatf.
friend GfQuatd operator/(const GfQuatd &q, double s)
Returns the product of quaternion q and scalar 1 / s.
Definition: quatd.h:234
void SetImaginary(double i, double j, double k)
Set the imaginary coefficients.
Definition: quatd.h:103
friend size_t hash_value(const GfQuatd &q)
Hash.
Definition: quatd.h:148
double GetLength() const
Return geometric length of this quaternion.
Definition: quatd.h:108
void SetReal(double real)
Set the real coefficient.
Definition: quatd.h:92
GfQuatd()=default
GfQuatd value-initializes to zero and performs no default initialization, like float or double.
friend GfQuatd operator+(const GfQuatd &q1, const GfQuatd &q2)
Component-wise binary sum operator.
Definition: quatd.h:204
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:43
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quath.h:44
Basic type for a vector of 3 double components.
Definition: vec3d.h:46
GfVec3d & Set(double s0, double s1, double s2)
Set all elements with passed arguments.
Definition: vec3d.h:113
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
double GfSqrt(double f)
Return sqrt(f).
Definition: math.h:187
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.
Definition: limits.h:17
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GF_API GfQuatd GfSlerp(double alpha, const GfQuatd &q0, const GfQuatd &q1)
Spherically linearly interpolate between q0 and q1.
double GfDot(const GfQuatd &q1, const GfQuatd &q2)
Return the dot (inner) product of two quaternions.
Definition: quatd.h:263
A metafunction with a static const bool member 'value' that is true for GfQuat types and false for al...
Definition: traits.h:30