File indexing completed on 2025-01-18 10:03:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_Hypr2d_HeaderFile
0016 #define _gp_Hypr2d_HeaderFile
0017
0018 #include <gp.hxx>
0019 #include <gp_Ax22d.hxx>
0020 #include <gp_Ax2d.hxx>
0021 #include <gp_Pnt2d.hxx>
0022 #include <Standard_DomainError.hxx>
0023 #include <Standard_ConstructionError.hxx>
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 class gp_Hypr2d
0066 {
0067 public:
0068
0069 DEFINE_STANDARD_ALLOC
0070
0071
0072 gp_Hypr2d()
0073 : majorRadius (RealLast()),
0074 minorRadius (RealLast())
0075 {}
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 gp_Hypr2d (const gp_Ax2d& theMajorAxis, const Standard_Real theMajorRadius,
0088 const Standard_Real theMinorRadius, const Standard_Boolean theIsSense = Standard_True)
0089 : majorRadius (theMajorRadius),
0090 minorRadius (theMinorRadius)
0091 {
0092 pos = gp_Ax22d (theMajorAxis, theIsSense);
0093 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0,
0094 "gp_Hypr2d() - invalid construction parameters");
0095 }
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 gp_Hypr2d (const gp_Ax22d& theA, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius)
0113 : pos (theA),
0114 majorRadius (theMajorRadius),
0115 minorRadius (theMinorRadius)
0116 {
0117 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0,
0118 "gp_Hypr2d() - invalid construction parameters");
0119 }
0120
0121
0122
0123 void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); }
0124
0125
0126
0127
0128
0129 void SetMajorRadius (const Standard_Real theMajorRadius)
0130 {
0131 Standard_ConstructionError_Raise_if (theMajorRadius < 0.0,
0132 "gp_Hypr2d::SetMajorRadius() - major radius should be greater or equal zero");
0133 majorRadius = theMajorRadius;
0134 }
0135
0136
0137
0138
0139
0140 void SetMinorRadius (const Standard_Real theMinorRadius)
0141 {
0142 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0,
0143 "gp_Hypr2d::SetMinorRadius() - minor radius should be greater or equal zero");
0144 minorRadius = theMinorRadius;
0145 }
0146
0147
0148
0149 void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); }
0150
0151
0152
0153 void SetXAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); }
0154
0155
0156
0157 void SetYAxis (const gp_Ax2d& theA) { pos.SetYAxis (theA); }
0158
0159
0160
0161
0162
0163
0164
0165 gp_Ax2d Asymptote1() const;
0166
0167
0168
0169
0170
0171
0172
0173 gp_Ax2d Asymptote2() const;
0174
0175
0176
0177
0178 Standard_EXPORT void Coefficients (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC,
0179 Standard_Real& theD, Standard_Real& theE, Standard_Real& theF) const;
0180
0181
0182
0183 gp_Hypr2d ConjugateBranch1() const
0184 {
0185 gp_Dir2d aV (pos.YDirection());
0186 Standard_Boolean isSign = (pos.XDirection().Crossed (pos.YDirection())) >= 0.0;
0187 return gp_Hypr2d (gp_Ax2d (pos.Location(), aV), minorRadius, majorRadius, isSign);
0188 }
0189
0190
0191
0192 gp_Hypr2d ConjugateBranch2() const
0193 {
0194 gp_Dir2d aV (pos.YDirection().Reversed());
0195 Standard_Boolean isSign = (pos.XDirection().Crossed (pos.YDirection())) >= 0.0;
0196 return gp_Hypr2d (gp_Ax2d (pos.Location(), aV), minorRadius, majorRadius, isSign);
0197 }
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207 gp_Ax2d Directrix1() const;
0208
0209
0210
0211 gp_Ax2d Directrix2() const;
0212
0213
0214
0215
0216 Standard_Real Eccentricity() const
0217 {
0218 Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(),
0219 "gp_Hypr2d::Eccentricity() - major radius is zero");
0220 return sqrt (majorRadius * majorRadius + minorRadius * minorRadius) / majorRadius;
0221 }
0222
0223
0224
0225 Standard_Real Focal() const
0226 {
0227 return 2.0 * sqrt (majorRadius * majorRadius + minorRadius * minorRadius);
0228 }
0229
0230
0231
0232 gp_Pnt2d Focus1() const
0233 {
0234 Standard_Real aC = sqrt (majorRadius * majorRadius + minorRadius * minorRadius);
0235 return gp_Pnt2d (pos.Location().X() + aC * pos.XDirection().X(), pos.Location().Y() + aC * pos.XDirection().Y());
0236 }
0237
0238
0239
0240 gp_Pnt2d Focus2() const
0241 {
0242 Standard_Real aC = sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
0243 return gp_Pnt2d(pos.Location().X() - aC * pos.XDirection().X(), pos.Location().Y() - aC * pos.XDirection().Y());
0244 }
0245
0246
0247
0248
0249 const gp_Pnt2d& Location() const { return pos.Location(); }
0250
0251
0252
0253 Standard_Real MajorRadius() const { return majorRadius; }
0254
0255
0256
0257 Standard_Real MinorRadius() const { return minorRadius; }
0258
0259
0260
0261
0262 gp_Hypr2d OtherBranch() const
0263 {
0264 Standard_Boolean isSign = (pos.XDirection().Crossed (pos.YDirection())) >= 0.0;
0265 return gp_Hypr2d (gp_Ax2d (pos.Location(), pos.XDirection().Reversed()), majorRadius, minorRadius, isSign);
0266 }
0267
0268
0269
0270
0271 Standard_Real Parameter() const
0272 {
0273 Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(),
0274 "gp_Hypr2d::Parameter() - major radius is zero");
0275 return (minorRadius * minorRadius) / majorRadius;
0276 }
0277
0278
0279 const gp_Ax22d& Axis() const { return pos; }
0280
0281
0282
0283
0284
0285
0286 gp_Ax2d XAxis() const { return pos.XAxis(); }
0287
0288
0289
0290
0291
0292
0293 gp_Ax2d YAxis() const { return pos.YAxis(); }
0294
0295 void Reverse()
0296 {
0297 gp_Dir2d aTemp = pos.YDirection();
0298 aTemp.Reverse();
0299 pos.SetAxis (gp_Ax22d(pos.Location(), pos.XDirection(), aTemp));
0300 }
0301
0302
0303
0304
0305
0306
0307
0308 Standard_NODISCARD gp_Hypr2d Reversed() const;
0309
0310
0311
0312 Standard_Boolean IsDirect() const
0313 {
0314 return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0;
0315 }
0316
0317 Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
0318
0319
0320
0321 Standard_NODISCARD Standard_EXPORT gp_Hypr2d Mirrored (const gp_Pnt2d& theP) const;
0322
0323 Standard_EXPORT void Mirror (const gp_Ax2d& theA);
0324
0325
0326
0327 Standard_NODISCARD Standard_EXPORT gp_Hypr2d Mirrored (const gp_Ax2d& theA) const;
0328
0329 void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) { pos.Rotate (theP, theAng); }
0330
0331
0332
0333 Standard_NODISCARD gp_Hypr2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
0334 {
0335 gp_Hypr2d aH = *this;
0336 aH.pos.Rotate (theP, theAng);
0337 return aH;
0338 }
0339
0340 void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
0341
0342
0343
0344
0345
0346 Standard_NODISCARD gp_Hypr2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const;
0347
0348 void Transform (const gp_Trsf2d& theT);
0349
0350
0351
0352 Standard_NODISCARD gp_Hypr2d Transformed (const gp_Trsf2d& theT) const;
0353
0354 void Translate (const gp_Vec2d& theV) { pos.Translate (theV); }
0355
0356
0357
0358 Standard_NODISCARD gp_Hypr2d Translated (const gp_Vec2d& theV) const
0359 {
0360 gp_Hypr2d aH = *this;
0361 aH.pos.Translate (theV);
0362 return aH;
0363 }
0364
0365 void Translate(const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); }
0366
0367
0368 Standard_NODISCARD gp_Hypr2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
0369 {
0370 gp_Hypr2d aH = *this;
0371 aH.pos.Translate (theP1, theP2);
0372 return aH;
0373 }
0374
0375 private:
0376
0377 gp_Ax22d pos;
0378 Standard_Real majorRadius;
0379 Standard_Real minorRadius;
0380
0381 };
0382
0383
0384
0385
0386
0387 inline gp_Ax2d gp_Hypr2d::Asymptote1() const
0388 {
0389 Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(),
0390 "gp_Hypr2d::Asymptote1() - major radius is zero");
0391 gp_Dir2d aVdir = pos.XDirection();
0392 gp_XY aCoord1 (pos.YDirection().XY());
0393 gp_XY aCoord2 = aCoord1.Multiplied (minorRadius / majorRadius);
0394 aCoord1.Add (aCoord2);
0395 aVdir.SetXY (aCoord1);
0396 return gp_Ax2d (pos.Location(), aVdir);
0397 }
0398
0399
0400
0401
0402
0403 inline gp_Ax2d gp_Hypr2d::Asymptote2() const
0404 {
0405 Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(),
0406 "gp_Hypr2d::Asymptote2() - major radius is zero");
0407 gp_Vec2d aVdir = pos.XDirection();
0408 gp_XY aCoord1 (pos.YDirection().XY());
0409 gp_XY aCoord2 = aCoord1.Multiplied (-minorRadius / majorRadius);
0410 aCoord1.Add (aCoord2);
0411 aVdir.SetXY (aCoord1);
0412 return gp_Ax2d (pos.Location(), aVdir);
0413 }
0414
0415
0416
0417
0418
0419 inline gp_Ax2d gp_Hypr2d::Directrix1() const
0420 {
0421 Standard_Real anE = Eccentricity();
0422 gp_XY anOrig = pos.XDirection().XY();
0423 anOrig.Multiply (majorRadius / anE);
0424 anOrig.Add (pos.Location().XY());
0425 return gp_Ax2d (gp_Pnt2d (anOrig), gp_Dir2d (pos.YDirection()));
0426 }
0427
0428
0429
0430
0431
0432 inline gp_Ax2d gp_Hypr2d::Directrix2() const
0433 {
0434 Standard_Real anE = Eccentricity();
0435 gp_XY anOrig = pos.XDirection().XY();
0436 anOrig.Multiply (Parameter() / anE);
0437 anOrig.Add (Focus1().XY());
0438 return gp_Ax2d (gp_Pnt2d (anOrig), gp_Dir2d (pos.YDirection()));
0439 }
0440
0441
0442
0443
0444
0445 inline gp_Hypr2d gp_Hypr2d::Reversed() const
0446 {
0447 gp_Hypr2d aH = *this;
0448 gp_Dir2d aTemp = pos.YDirection();
0449 aTemp.Reverse ();
0450 aH.pos.SetAxis (gp_Ax22d (pos.Location(),pos.XDirection(), aTemp));
0451 return aH;
0452 }
0453
0454
0455
0456
0457
0458 inline void gp_Hypr2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
0459 {
0460 majorRadius *= theS;
0461 if (majorRadius < 0)
0462 {
0463 majorRadius = -majorRadius;
0464 }
0465 minorRadius *= theS;
0466 if (minorRadius < 0)
0467 {
0468 minorRadius = -minorRadius;
0469 }
0470 pos.Scale (theP, theS);
0471 }
0472
0473
0474
0475
0476
0477 inline gp_Hypr2d gp_Hypr2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
0478 {
0479 gp_Hypr2d aH = *this;
0480 aH.majorRadius *= theS;
0481 if (aH.majorRadius < 0)
0482 {
0483 aH.majorRadius = -aH.majorRadius;
0484 }
0485 aH.minorRadius *= theS;
0486 if (aH.minorRadius < 0)
0487 {
0488 aH.minorRadius = -aH.minorRadius;
0489 }
0490 aH.pos.Scale (theP, theS);
0491 return aH;
0492 }
0493
0494
0495
0496
0497
0498 inline void gp_Hypr2d::Transform (const gp_Trsf2d& theT)
0499 {
0500 majorRadius *= theT.ScaleFactor();
0501 if (majorRadius < 0)
0502 {
0503 majorRadius = -majorRadius;
0504 }
0505 minorRadius *= theT.ScaleFactor();
0506 if (minorRadius < 0)
0507 {
0508 minorRadius = -minorRadius;
0509 }
0510 pos.Transform (theT);
0511 }
0512
0513
0514
0515
0516
0517 inline gp_Hypr2d gp_Hypr2d::Transformed (const gp_Trsf2d& theT) const
0518 {
0519 gp_Hypr2d aH = *this;
0520 aH.majorRadius *= theT.ScaleFactor();
0521 if (aH.majorRadius < 0)
0522 {
0523 aH.majorRadius = -aH.majorRadius;
0524 }
0525 aH.minorRadius *= theT.ScaleFactor();
0526 if (aH.minorRadius < 0)
0527 {
0528 aH.minorRadius = -aH.minorRadius;
0529 }
0530 aH.pos.Transform (theT);
0531 return aH;
0532 }
0533
0534 #endif