File indexing completed on 2025-01-18 10:03:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_XYZ_HeaderFile
0016 #define _gp_XYZ_HeaderFile
0017
0018 #include <gp.hxx>
0019 #include <gp_Mat.hxx>
0020 #include <Standard_ConstructionError.hxx>
0021 #include <Standard_OutOfRange.hxx>
0022 #include <Standard_OStream.hxx>
0023 #include <Standard_SStream.hxx>
0024
0025
0026
0027
0028
0029
0030
0031 class gp_XYZ
0032 {
0033 public:
0034
0035 DEFINE_STANDARD_ALLOC
0036
0037
0038 gp_XYZ()
0039 : x (0.),
0040 y (0.),
0041 z (0.)
0042 {}
0043
0044
0045 gp_XYZ (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ)
0046 : x (theX),
0047 y (theY),
0048 z (theZ)
0049 {}
0050
0051
0052
0053 void SetCoord (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ)
0054 {
0055 x = theX;
0056 y = theY;
0057 z = theZ;
0058 }
0059
0060
0061
0062
0063
0064
0065 void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi)
0066 {
0067 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 3, NULL);
0068 (&x)[theIndex - 1] = theXi;
0069 }
0070
0071
0072 void SetX (const Standard_Real theX) { x = theX; }
0073
0074
0075 void SetY (const Standard_Real theY) { y = theY; }
0076
0077
0078 void SetZ (const Standard_Real theZ) { z = theZ; }
0079
0080
0081
0082
0083
0084
0085
0086 Standard_Real Coord (const Standard_Integer theIndex) const
0087 {
0088 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 3, NULL);
0089 return (&x)[theIndex - 1];
0090 }
0091
0092 Standard_Real& ChangeCoord (const Standard_Integer theIndex)
0093 {
0094 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 3, NULL);
0095 return (&x)[theIndex - 1];
0096 }
0097
0098 void Coord (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const
0099 {
0100 theX = x;
0101 theY = y;
0102 theZ = z;
0103 }
0104
0105
0106
0107
0108 const Standard_Real* GetData() const { return (&x); }
0109
0110
0111
0112
0113 Standard_Real* ChangeData() { return (&x); }
0114
0115
0116 Standard_Real X() const { return x; }
0117
0118
0119 Standard_Real Y() const { return y; }
0120
0121
0122 Standard_Real Z() const { return z; }
0123
0124
0125 Standard_Real Modulus() const { return sqrt (x * x + y * y + z * z); }
0126
0127
0128 Standard_Real SquareModulus() const { return (x * x + y * y + z * z); }
0129
0130
0131
0132
0133
0134
0135
0136 Standard_EXPORT Standard_Boolean IsEqual (const gp_XYZ& theOther, const Standard_Real theTolerance) const;
0137
0138
0139
0140
0141
0142
0143 void Add (const gp_XYZ& theOther)
0144 {
0145 x += theOther.x;
0146 y += theOther.y;
0147 z += theOther.z;
0148 }
0149
0150 void operator+= (const gp_XYZ& theOther) { Add (theOther); }
0151
0152
0153
0154
0155
0156
0157 Standard_NODISCARD gp_XYZ Added (const gp_XYZ& theOther) const
0158 {
0159 return gp_XYZ (x + theOther.x, y + theOther.y, z + theOther.z);
0160 }
0161
0162 Standard_NODISCARD gp_XYZ operator + (const gp_XYZ& theOther) const { return Added (theOther); }
0163
0164
0165
0166
0167
0168
0169 void Cross (const gp_XYZ& theOther);
0170
0171 void operator^= (const gp_XYZ& theOther) { Cross (theOther); }
0172
0173
0174
0175
0176
0177
0178 Standard_NODISCARD gp_XYZ Crossed (const gp_XYZ& theOther) const
0179 {
0180 return gp_XYZ (y * theOther.z - z * theOther.y,
0181 z * theOther.x - x * theOther.z,
0182 x * theOther.y - y * theOther.x);
0183 }
0184
0185 Standard_NODISCARD gp_XYZ operator ^ (const gp_XYZ& theOther) const { return Crossed (theOther); }
0186
0187
0188
0189 Standard_Real CrossMagnitude (const gp_XYZ& theRight) const;
0190
0191
0192
0193 Standard_Real CrossSquareMagnitude (const gp_XYZ& theRight) const;
0194
0195
0196
0197 void CrossCross (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2);
0198
0199
0200
0201 Standard_NODISCARD gp_XYZ CrossCrossed (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) const
0202 {
0203 gp_XYZ aCoord0 = *this;
0204 aCoord0.CrossCross (theCoord1, theCoord2);
0205 return aCoord0;
0206 }
0207
0208
0209 void Divide (const Standard_Real theScalar)
0210 {
0211 x /= theScalar;
0212 y /= theScalar;
0213 z /= theScalar;
0214 }
0215
0216 void operator/= (const Standard_Real theScalar) { Divide (theScalar); }
0217
0218
0219 Standard_NODISCARD gp_XYZ Divided (const Standard_Real theScalar) const { return gp_XYZ (x / theScalar, y / theScalar, z / theScalar); }
0220
0221 Standard_NODISCARD gp_XYZ operator/ (const Standard_Real theScalar) const { return Divided (theScalar); }
0222
0223
0224 Standard_Real Dot (const gp_XYZ& theOther) const { return(x * theOther.x + y * theOther.y + z * theOther.z); }
0225
0226 Standard_Real operator* (const gp_XYZ& theOther) const { return Dot (theOther); }
0227
0228
0229 Standard_Real DotCross (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) const;
0230
0231
0232
0233
0234
0235
0236 void Multiply (const Standard_Real theScalar)
0237 {
0238 x *= theScalar;
0239 y *= theScalar;
0240 z *= theScalar;
0241 }
0242
0243 void operator*= (const Standard_Real theScalar) { Multiply (theScalar); }
0244
0245
0246
0247
0248
0249
0250 void Multiply (const gp_XYZ& theOther)
0251 {
0252 x *= theOther.x;
0253 y *= theOther.y;
0254 z *= theOther.z;
0255 }
0256
0257 void operator*= (const gp_XYZ& theOther) { Multiply (theOther); }
0258
0259
0260 void Multiply (const gp_Mat& theMatrix);
0261
0262 void operator*= (const gp_Mat& theMatrix) { Multiply (theMatrix); }
0263
0264
0265
0266
0267
0268
0269 Standard_NODISCARD gp_XYZ Multiplied (const Standard_Real theScalar) const { return gp_XYZ (x * theScalar, y * theScalar, z * theScalar); }
0270
0271 Standard_NODISCARD gp_XYZ operator* (const Standard_Real theScalar) const { return Multiplied (theScalar); }
0272
0273
0274
0275
0276
0277
0278 Standard_NODISCARD gp_XYZ Multiplied (const gp_XYZ& theOther) const { return gp_XYZ (x * theOther.x, y * theOther.y, z * theOther.z); }
0279
0280
0281 Standard_NODISCARD gp_XYZ Multiplied (const gp_Mat& theMatrix) const
0282 {
0283 return gp_XYZ (theMatrix.Value (1, 1) * x + theMatrix.Value (1, 2) * y + theMatrix.Value (1, 3) * z,
0284 theMatrix.Value (2, 1) * x + theMatrix.Value (2, 2) * y + theMatrix.Value (2, 3) * z,
0285 theMatrix.Value (3, 1) * x + theMatrix.Value (3, 2) * y + theMatrix.Value (3, 3) * z);
0286 }
0287
0288 Standard_NODISCARD gp_XYZ operator* (const gp_Mat& theMatrix) const { return Multiplied (theMatrix); }
0289
0290
0291
0292
0293
0294
0295
0296 void Normalize();
0297
0298
0299
0300
0301
0302
0303
0304 Standard_NODISCARD gp_XYZ Normalized() const
0305 {
0306 Standard_Real aD = Modulus();
0307 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_XYZ::Normalized() - vector has zero norm");
0308 return gp_XYZ(x / aD, y / aD, z / aD);
0309 }
0310
0311
0312
0313
0314
0315
0316 void Reverse()
0317 {
0318 x = -x;
0319 y = -y;
0320 z = -z;
0321 }
0322
0323
0324
0325
0326
0327
0328 Standard_NODISCARD gp_XYZ Reversed() const { return gp_XYZ (-x, -y, -z); }
0329
0330
0331
0332
0333
0334
0335 void Subtract (const gp_XYZ& theOther)
0336 {
0337 x -= theOther.x;
0338 y -= theOther.y;
0339 z -= theOther.z;
0340 }
0341
0342 void operator-= (const gp_XYZ& theOther) { Subtract (theOther); }
0343
0344
0345
0346
0347
0348
0349 Standard_NODISCARD gp_XYZ Subtracted (const gp_XYZ& theOther) const { return gp_XYZ (x - theOther.x, y - theOther.y, z - theOther.z); }
0350
0351 Standard_NODISCARD gp_XYZ operator- (const gp_XYZ& theOther) const { return Subtracted (theOther); }
0352
0353
0354
0355
0356
0357 void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1,
0358 const Standard_Real theA2, const gp_XYZ& theXYZ2,
0359 const Standard_Real theA3, const gp_XYZ& theXYZ3,
0360 const gp_XYZ& theXYZ4)
0361 {
0362 x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theA3 * theXYZ3.x + theXYZ4.x;
0363 y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theA3 * theXYZ3.y + theXYZ4.y;
0364 z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theA3 * theXYZ3.z + theXYZ4.z;
0365 }
0366
0367
0368
0369
0370
0371 void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1,
0372 const Standard_Real theA2, const gp_XYZ& theXYZ2,
0373 const Standard_Real theA3, const gp_XYZ& theXYZ3)
0374 {
0375 x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theA3 * theXYZ3.x;
0376 y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theA3 * theXYZ3.y;
0377 z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theA3 * theXYZ3.z;
0378 }
0379
0380
0381
0382
0383
0384 void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1,
0385 const Standard_Real theA2, const gp_XYZ& theXYZ2,
0386 const gp_XYZ& theXYZ3)
0387 {
0388 x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theXYZ3.x;
0389 y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theXYZ3.y;
0390 z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theXYZ3.z;
0391 }
0392
0393
0394
0395
0396
0397 void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1,
0398 const Standard_Real theA2, const gp_XYZ& theXYZ2)
0399 {
0400 x = theA1 * theXYZ1.x + theA2 * theXYZ2.x;
0401 y = theA1 * theXYZ1.y + theA2 * theXYZ2.y;
0402 z = theA1 * theXYZ1.z + theA2 * theXYZ2.z;
0403 }
0404
0405
0406
0407
0408
0409 void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1,
0410 const gp_XYZ& theXYZ2)
0411 {
0412 x = theA1 * theXYZ1.x + theXYZ2.x;
0413 y = theA1 * theXYZ1.y + theXYZ2.y;
0414 z = theA1 * theXYZ1.z + theXYZ2.z;
0415 }
0416
0417
0418
0419
0420
0421 void SetLinearForm (const gp_XYZ& theXYZ1, const gp_XYZ& theXYZ2)
0422 {
0423 x = theXYZ1.x + theXYZ2.x;
0424 y = theXYZ1.y + theXYZ2.y;
0425 z = theXYZ1.z + theXYZ2.z;
0426 }
0427
0428
0429 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0430
0431
0432 Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
0433
0434 private:
0435
0436 Standard_Real x;
0437 Standard_Real y;
0438 Standard_Real z;
0439
0440 };
0441
0442
0443
0444
0445
0446 inline void gp_XYZ::Cross (const gp_XYZ& theRight)
0447 {
0448 Standard_Real aXresult = y * theRight.z - z * theRight.y;
0449 Standard_Real aYresult = z * theRight.x - x * theRight.z;
0450 z = x * theRight.y - y * theRight.x;
0451 x = aXresult;
0452 y = aYresult;
0453 }
0454
0455
0456
0457
0458
0459 inline Standard_Real gp_XYZ::CrossMagnitude (const gp_XYZ& theRight) const
0460 {
0461 Standard_Real aXresult = y * theRight.z - z * theRight.y;
0462 Standard_Real aYresult = z * theRight.x - x * theRight.z;
0463 Standard_Real aZresult = x * theRight.y - y * theRight.x;
0464 return sqrt (aXresult * aXresult + aYresult * aYresult + aZresult * aZresult);
0465 }
0466
0467
0468
0469
0470
0471 inline Standard_Real gp_XYZ::CrossSquareMagnitude (const gp_XYZ& theRight) const
0472 {
0473 Standard_Real aXresult = y * theRight.z - z * theRight.y;
0474 Standard_Real aYresult = z * theRight.x - x * theRight.z;
0475 Standard_Real aZresult = x * theRight.y - y * theRight.x;
0476 return aXresult * aXresult + aYresult * aYresult + aZresult * aZresult;
0477 }
0478
0479
0480
0481
0482
0483 inline void gp_XYZ::CrossCross (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2)
0484 {
0485 Standard_Real aXresult = y * (theCoord1.x * theCoord2.y - theCoord1.y * theCoord2.x) -
0486 z * (theCoord1.z * theCoord2.x - theCoord1.x * theCoord2.z);
0487 Standard_Real anYresult = z * (theCoord1.y * theCoord2.z - theCoord1.z * theCoord2.y) -
0488 x * (theCoord1.x * theCoord2.y - theCoord1.y * theCoord2.x);
0489 z = x * (theCoord1.z * theCoord2.x - theCoord1.x * theCoord2.z) -
0490 y * (theCoord1.y * theCoord2.z - theCoord1.z * theCoord2.y);
0491 x = aXresult;
0492 y = anYresult;
0493 }
0494
0495
0496
0497
0498
0499 inline Standard_Real gp_XYZ::DotCross (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) const
0500 {
0501 Standard_Real aXresult = theCoord1.y * theCoord2.z - theCoord1.z * theCoord2.y;
0502 Standard_Real anYresult = theCoord1.z * theCoord2.x - theCoord1.x * theCoord2.z;
0503 Standard_Real aZresult = theCoord1.x * theCoord2.y - theCoord1.y * theCoord2.x;
0504 return (x * aXresult + y * anYresult + z * aZresult);
0505 }
0506
0507
0508
0509
0510
0511 inline void gp_XYZ::Multiply (const gp_Mat& theMatrix)
0512 {
0513 Standard_Real aXresult = theMatrix.Value (1, 1) * x + theMatrix.Value (1, 2) * y + theMatrix.Value (1, 3) * z;
0514 Standard_Real anYresult = theMatrix.Value (2, 1) * x + theMatrix.Value (2, 2) * y + theMatrix.Value (2, 3) * z;
0515 z = theMatrix.Value (3, 1) * x + theMatrix.Value (3, 2) * y + theMatrix.Value (3, 3) * z;
0516 x = aXresult;
0517 y = anYresult;
0518 }
0519
0520
0521
0522
0523
0524 inline void gp_XYZ::Normalize()
0525 {
0526 Standard_Real aD = Modulus();
0527 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_XYZ::Normalize() - vector has zero norm");
0528 x = x / aD;
0529 y = y / aD;
0530 z = z / aD;
0531 }
0532
0533
0534
0535
0536
0537 inline gp_XYZ operator* (const gp_Mat& theMatrix, const gp_XYZ& theCoord1)
0538 {
0539 return theCoord1.Multiplied (theMatrix);
0540 }
0541
0542
0543
0544
0545
0546 inline gp_XYZ operator* (const Standard_Real theScalar, const gp_XYZ& theCoord1)
0547 {
0548 return theCoord1.Multiplied (theScalar);
0549 }
0550
0551 #endif