File indexing completed on 2026-09-09 09:15:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _gp_Quaternion_HeaderFile
0017 #define _gp_Quaternion_HeaderFile
0018
0019 #include <gp_EulerSequence.hxx>
0020 #include <gp_Mat.hxx>
0021 #include <gp_Vec.hxx>
0022
0023
0024
0025
0026
0027
0028
0029
0030 class gp_Quaternion
0031 {
0032 public:
0033 DEFINE_STANDARD_ALLOC
0034
0035
0036 gp_Quaternion()
0037 : x(0.0),
0038 y(0.0),
0039 z(0.0),
0040 w(1.0)
0041 {
0042 }
0043
0044
0045 gp_Quaternion(const Standard_Real theX,
0046 const Standard_Real theY,
0047 const Standard_Real theZ,
0048 const Standard_Real theW)
0049 : x(theX),
0050 y(theY),
0051 z(theZ),
0052 w(theW)
0053 {
0054 }
0055
0056
0057
0058 gp_Quaternion(const gp_Vec& theVecFrom, const gp_Vec& theVecTo)
0059 {
0060 SetRotation(theVecFrom, theVecTo);
0061 }
0062
0063
0064
0065
0066
0067
0068 gp_Quaternion(const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec)
0069 {
0070 SetRotation(theVecFrom, theVecTo, theHelpCrossVec);
0071 }
0072
0073
0074
0075 gp_Quaternion(const gp_Vec& theAxis, const Standard_Real theAngle)
0076 {
0077 SetVectorAndAngle(theAxis, theAngle);
0078 }
0079
0080
0081
0082 gp_Quaternion(const gp_Mat& theMat) { SetMatrix(theMat); }
0083
0084
0085 Standard_EXPORT Standard_Boolean IsEqual(const gp_Quaternion& theOther) const;
0086
0087
0088
0089
0090
0091 Standard_EXPORT void SetRotation(const gp_Vec& theVecFrom, const gp_Vec& theVecTo);
0092
0093
0094
0095
0096
0097 Standard_EXPORT void SetRotation(const gp_Vec& theVecFrom,
0098 const gp_Vec& theVecTo,
0099 const gp_Vec& theHelpCrossVec);
0100
0101
0102 Standard_EXPORT void SetVectorAndAngle(const gp_Vec& theAxis, const Standard_Real theAngle);
0103
0104
0105
0106 Standard_EXPORT void GetVectorAndAngle(gp_Vec& theAxis, Standard_Real& theAngle) const;
0107
0108
0109
0110
0111
0112
0113 Standard_EXPORT void SetMatrix(const gp_Mat& theMat);
0114
0115
0116 Standard_EXPORT gp_Mat GetMatrix() const;
0117
0118
0119
0120 Standard_EXPORT void SetEulerAngles(const gp_EulerSequence theOrder,
0121 const Standard_Real theAlpha,
0122 const Standard_Real theBeta,
0123 const Standard_Real theGamma);
0124
0125
0126 Standard_EXPORT void GetEulerAngles(const gp_EulerSequence theOrder,
0127 Standard_Real& theAlpha,
0128 Standard_Real& theBeta,
0129 Standard_Real& theGamma) const;
0130
0131 void Set(const Standard_Real theX,
0132 const Standard_Real theY,
0133 const Standard_Real theZ,
0134 const Standard_Real theW);
0135
0136 void Set(const gp_Quaternion& theQuaternion);
0137
0138 Standard_Real X() const { return x; }
0139
0140 Standard_Real Y() const { return y; }
0141
0142 Standard_Real Z() const { return z; }
0143
0144 Standard_Real W() const { return w; }
0145
0146
0147 void SetIdent()
0148 {
0149 x = y = z = 0.0;
0150 w = 1.0;
0151 }
0152
0153
0154 void Reverse()
0155 {
0156 x = -x;
0157 y = -y;
0158 z = -z;
0159 }
0160
0161
0162 Standard_NODISCARD gp_Quaternion Reversed() const { return gp_Quaternion(-x, -y, -z, w); }
0163
0164
0165 void Invert()
0166 {
0167 Standard_Real anIn = 1.0 / SquareNorm();
0168 Set(-x * anIn, -y * anIn, -z * anIn, w * anIn);
0169 }
0170
0171
0172 Standard_NODISCARD gp_Quaternion Inverted() const
0173 {
0174 Standard_Real anIn = 1.0 / SquareNorm();
0175 return gp_Quaternion(-x * anIn, -y * anIn, -z * anIn, w * anIn);
0176 }
0177
0178
0179 Standard_Real SquareNorm() const { return x * x + y * y + z * z + w * w; }
0180
0181
0182 Standard_Real Norm() const { return Sqrt(SquareNorm()); }
0183
0184
0185
0186 void Scale(const Standard_Real theScale);
0187
0188 void operator*=(const Standard_Real theScale) { Scale(theScale); }
0189
0190
0191 Standard_NODISCARD gp_Quaternion Scaled(const Standard_Real theScale) const
0192 {
0193 return gp_Quaternion(x * theScale, y * theScale, z * theScale, w * theScale);
0194 }
0195
0196 Standard_NODISCARD gp_Quaternion operator*(const Standard_Real theScale) const
0197 {
0198 return Scaled(theScale);
0199 }
0200
0201
0202
0203
0204 Standard_EXPORT void StabilizeLength();
0205
0206
0207
0208
0209 Standard_EXPORT void Normalize();
0210
0211
0212 Standard_NODISCARD gp_Quaternion Normalized() const
0213 {
0214 gp_Quaternion aNormilizedQ(*this);
0215 aNormilizedQ.Normalize();
0216 return aNormilizedQ;
0217 }
0218
0219
0220
0221
0222 Standard_NODISCARD gp_Quaternion Negated() const { return gp_Quaternion(-x, -y, -z, -w); }
0223
0224 Standard_NODISCARD gp_Quaternion operator-() const { return Negated(); }
0225
0226
0227 Standard_NODISCARD gp_Quaternion Added(const gp_Quaternion& theOther) const
0228 {
0229 return gp_Quaternion(x + theOther.x, y + theOther.y, z + theOther.z, w + theOther.w);
0230 }
0231
0232 Standard_NODISCARD gp_Quaternion operator+(const gp_Quaternion& theOther) const
0233 {
0234 return Added(theOther);
0235 }
0236
0237
0238 Standard_NODISCARD gp_Quaternion Subtracted(const gp_Quaternion& theOther) const
0239 {
0240 return gp_Quaternion(x - theOther.x, y - theOther.y, z - theOther.z, w - theOther.w);
0241 }
0242
0243 Standard_NODISCARD gp_Quaternion operator-(const gp_Quaternion& theOther) const
0244 {
0245 return Subtracted(theOther);
0246 }
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258 Standard_NODISCARD gp_Quaternion Multiplied(const gp_Quaternion& theOther) const;
0259
0260 Standard_NODISCARD gp_Quaternion operator*(const gp_Quaternion& theOther) const
0261 {
0262 return Multiplied(theOther);
0263 }
0264
0265
0266 void Add(const gp_Quaternion& theOther);
0267
0268 void operator+=(const gp_Quaternion& theOther) { Add(theOther); }
0269
0270
0271 void Subtract(const gp_Quaternion& theOther);
0272
0273 void operator-=(const gp_Quaternion& theOther) { Subtract(theOther); }
0274
0275
0276 void Multiply(const gp_Quaternion& theOther)
0277 {
0278 (*this) = Multiplied(theOther);
0279 }
0280
0281 void operator*=(const gp_Quaternion& theOther) { Multiply(theOther); }
0282
0283
0284 Standard_Real Dot(const gp_Quaternion& theOther) const
0285 {
0286 return x * theOther.x + y * theOther.y + z * theOther.z + w * theOther.w;
0287 }
0288
0289
0290 Standard_EXPORT Standard_Real GetRotationAngle() const;
0291
0292
0293 Standard_EXPORT gp_Vec Multiply(const gp_Vec& theVec) const;
0294
0295 gp_Vec operator*(const gp_Vec& theVec) const { return Multiply(theVec); }
0296
0297 private:
0298 Standard_Real x;
0299 Standard_Real y;
0300 Standard_Real z;
0301 Standard_Real w;
0302 };
0303
0304
0305
0306
0307
0308 inline void gp_Quaternion::Set(Standard_Real theX,
0309 Standard_Real theY,
0310 Standard_Real theZ,
0311 Standard_Real theW)
0312 {
0313 this->x = theX;
0314 this->y = theY;
0315 this->z = theZ;
0316 this->w = theW;
0317 }
0318
0319
0320
0321
0322
0323 inline void gp_Quaternion::Set(const gp_Quaternion& theQuaternion)
0324 {
0325 x = theQuaternion.x;
0326 y = theQuaternion.y;
0327 z = theQuaternion.z;
0328 w = theQuaternion.w;
0329 }
0330
0331
0332
0333
0334
0335 inline void gp_Quaternion::Scale(const Standard_Real theScale)
0336 {
0337 x *= theScale;
0338 y *= theScale;
0339 z *= theScale;
0340 w *= theScale;
0341 }
0342
0343
0344
0345
0346
0347 inline gp_Quaternion gp_Quaternion::Multiplied(const gp_Quaternion& theQ) const
0348 {
0349 return gp_Quaternion(w * theQ.x + x * theQ.w + y * theQ.z - z * theQ.y,
0350 w * theQ.y + y * theQ.w + z * theQ.x - x * theQ.z,
0351 w * theQ.z + z * theQ.w + x * theQ.y - y * theQ.x,
0352 w * theQ.w - x * theQ.x - y * theQ.y - z * theQ.z);
0353
0354 }
0355
0356
0357
0358
0359
0360 inline void gp_Quaternion::Add(const gp_Quaternion& theQ)
0361 {
0362 x += theQ.x;
0363 y += theQ.y;
0364 z += theQ.z;
0365 w += theQ.w;
0366 }
0367
0368
0369
0370
0371
0372 inline void gp_Quaternion::Subtract(const gp_Quaternion& theQ)
0373 {
0374 x -= theQ.x;
0375 y -= theQ.y;
0376 z -= theQ.z;
0377 w -= theQ.w;
0378 }
0379
0380 #endif