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