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