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