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