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