Warning, file /include/opencascade/gp_Elips.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_Elips_HeaderFile
0016 #define _gp_Elips_HeaderFile
0017
0018 #include <gp.hxx>
0019 #include <gp_Ax1.hxx>
0020 #include <gp_Ax2.hxx>
0021 #include <gp_Pnt.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
0045
0046
0047
0048
0049 class gp_Elips
0050 {
0051 public:
0052 DEFINE_STANDARD_ALLOC
0053
0054
0055 constexpr gp_Elips() noexcept
0056 : majorRadius(RealLast()),
0057 minorRadius(RealSmall())
0058 {
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 constexpr gp_Elips(const gp_Ax2& theA2, const double theMajorRadius, const double theMinorRadius)
0070 : pos(theA2),
0071 majorRadius(theMajorRadius),
0072 minorRadius(theMinorRadius)
0073 {
0074 Standard_ConstructionError_Raise_if(theMinorRadius < 0.0 || theMajorRadius < theMinorRadius,
0075 "gp_Elips() - invalid construction parameters");
0076 }
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 void SetAxis(const gp_Ax1& theA1) { pos.SetAxis(theA1); }
0088
0089
0090
0091 constexpr void SetLocation(const gp_Pnt& theP) noexcept { pos.SetLocation(theP); }
0092
0093
0094
0095
0096 void SetMajorRadius(const double theMajorRadius)
0097 {
0098 Standard_ConstructionError_Raise_if(
0099 theMajorRadius < minorRadius,
0100 "gp_Elips::SetMajorRadius() - major radius should be greater or equal to minor radius");
0101 majorRadius = theMajorRadius;
0102 }
0103
0104
0105
0106
0107 void SetMinorRadius(const double theMinorRadius)
0108 {
0109 Standard_ConstructionError_Raise_if(theMinorRadius < 0.0 || majorRadius < theMinorRadius,
0110 "gp_Elips::SetMinorRadius() - minor radius should be a "
0111 "positive number lesser or equal to major radius");
0112 minorRadius = theMinorRadius;
0113 }
0114
0115
0116
0117 constexpr void SetPosition(const gp_Ax2& theA2) noexcept { pos = theA2; }
0118
0119
0120 constexpr double Area() const noexcept { return M_PI * majorRadius * minorRadius; }
0121
0122
0123 constexpr const gp_Ax1& Axis() const noexcept { return pos.Axis(); }
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 gp_Ax1 Directrix1() const;
0140
0141
0142
0143
0144
0145
0146 gp_Ax1 Directrix2() const;
0147
0148
0149
0150
0151
0152 double Eccentricity() const;
0153
0154
0155
0156 double Focal() const { return 2.0 * sqrt(majorRadius * majorRadius - minorRadius * minorRadius); }
0157
0158
0159
0160 gp_Pnt Focus1() const;
0161
0162
0163
0164 gp_Pnt Focus2() const;
0165
0166
0167
0168 constexpr const gp_Pnt& Location() const noexcept { return pos.Location(); }
0169
0170
0171 constexpr double MajorRadius() const noexcept { return majorRadius; }
0172
0173
0174 constexpr double MinorRadius() const noexcept { return minorRadius; }
0175
0176
0177
0178
0179 double Parameter() const;
0180
0181
0182 constexpr const gp_Ax2& Position() const noexcept { return pos; }
0183
0184
0185
0186
0187 constexpr gp_Ax1 XAxis() const noexcept { return gp_Ax1(pos.Location(), pos.XDirection()); }
0188
0189
0190
0191
0192 constexpr gp_Ax1 YAxis() const noexcept { return gp_Ax1(pos.Location(), pos.YDirection()); }
0193
0194 Standard_EXPORT void Mirror(const gp_Pnt& theP) noexcept;
0195
0196
0197
0198 [[nodiscard]] Standard_EXPORT gp_Elips Mirrored(const gp_Pnt& theP) const noexcept;
0199
0200 Standard_EXPORT void Mirror(const gp_Ax1& theA1);
0201
0202
0203
0204 [[nodiscard]] Standard_EXPORT gp_Elips Mirrored(const gp_Ax1& theA1) const;
0205
0206 Standard_EXPORT void Mirror(const gp_Ax2& theA2);
0207
0208
0209
0210
0211 [[nodiscard]] Standard_EXPORT gp_Elips Mirrored(const gp_Ax2& theA2) const;
0212
0213 void Rotate(const gp_Ax1& theA1, const double theAng) { pos.Rotate(theA1, theAng); }
0214
0215
0216
0217 [[nodiscard]] gp_Elips Rotated(const gp_Ax1& theA1, const double theAng) const
0218 {
0219 gp_Elips anE = *this;
0220 anE.pos.Rotate(theA1, theAng);
0221 return anE;
0222 }
0223
0224 void Scale(const gp_Pnt& theP, const double theS);
0225
0226
0227 [[nodiscard]] gp_Elips Scaled(const gp_Pnt& theP, const double theS) const;
0228
0229 void Transform(const gp_Trsf& theT);
0230
0231
0232 [[nodiscard]] gp_Elips Transformed(const gp_Trsf& theT) const;
0233
0234 constexpr void Translate(const gp_Vec& theV) noexcept { pos.Translate(theV); }
0235
0236
0237
0238 [[nodiscard]] constexpr gp_Elips Translated(const gp_Vec& theV) const noexcept
0239 {
0240 gp_Elips anE = *this;
0241 anE.pos.Translate(theV);
0242 return anE;
0243 }
0244
0245 constexpr void Translate(const gp_Pnt& theP1, const gp_Pnt& theP2) noexcept
0246 {
0247 pos.Translate(theP1, theP2);
0248 }
0249
0250
0251 [[nodiscard]] constexpr gp_Elips Translated(const gp_Pnt& theP1,
0252 const gp_Pnt& theP2) const noexcept
0253 {
0254 gp_Elips anE = *this;
0255 anE.pos.Translate(theP1, theP2);
0256 return anE;
0257 }
0258
0259 private:
0260 gp_Ax2 pos;
0261 double majorRadius;
0262 double minorRadius;
0263 };
0264
0265
0266
0267 inline gp_Ax1 gp_Elips::Directrix1() const
0268 {
0269 double anE = Eccentricity();
0270 Standard_ConstructionError_Raise_if(anE <= gp::Resolution(),
0271 "gp_Elips::Directrix1() - zero eccentricity");
0272 gp_XYZ anOrig = pos.XDirection().XYZ();
0273 anOrig.Multiply(majorRadius / anE);
0274 anOrig.Add(pos.Location().XYZ());
0275 return gp_Ax1(gp_Pnt(anOrig), pos.YDirection());
0276 }
0277
0278
0279
0280 inline gp_Ax1 gp_Elips::Directrix2() const
0281 {
0282 double anE = Eccentricity();
0283 Standard_ConstructionError_Raise_if(anE <= gp::Resolution(),
0284 "gp_Elips::Directrix2() - zero eccentricity");
0285 gp_XYZ anOrig = pos.XDirection().XYZ();
0286 anOrig.Multiply(-majorRadius / anE);
0287 anOrig.Add(pos.Location().XYZ());
0288 return gp_Ax1(gp_Pnt(anOrig), pos.YDirection());
0289 }
0290
0291
0292
0293 inline double gp_Elips::Eccentricity() const
0294 {
0295 if (majorRadius == 0.0)
0296 {
0297 return 0.0;
0298 }
0299 else
0300 {
0301 return sqrt(majorRadius * majorRadius - minorRadius * minorRadius) / majorRadius;
0302 }
0303 }
0304
0305
0306
0307 inline gp_Pnt gp_Elips::Focus1() const
0308 {
0309 double aC = sqrt(majorRadius * majorRadius - minorRadius * minorRadius);
0310 const gp_Pnt& aPP = pos.Location();
0311 const gp_Dir& aDD = pos.XDirection();
0312 return gp_Pnt(aPP.X() + aC * aDD.X(), aPP.Y() + aC * aDD.Y(), aPP.Z() + aC * aDD.Z());
0313 }
0314
0315
0316
0317 inline gp_Pnt gp_Elips::Focus2() const
0318 {
0319 double aC = sqrt(majorRadius * majorRadius - minorRadius * minorRadius);
0320 const gp_Pnt& aPP = pos.Location();
0321 const gp_Dir& aDD = pos.XDirection();
0322 return gp_Pnt(aPP.X() - aC * aDD.X(), aPP.Y() - aC * aDD.Y(), aPP.Z() - aC * aDD.Z());
0323 }
0324
0325
0326
0327 inline double gp_Elips::Parameter() const
0328 {
0329 if (majorRadius == 0.0)
0330 {
0331 return 0.0;
0332 }
0333 else
0334 {
0335 return (minorRadius * minorRadius) / majorRadius;
0336 }
0337 }
0338
0339
0340
0341 inline void gp_Elips::Scale(const gp_Pnt& theP, const double theS)
0342
0343
0344 {
0345 majorRadius *= theS;
0346 if (majorRadius < 0)
0347 {
0348 majorRadius = -majorRadius;
0349 }
0350 minorRadius *= theS;
0351 if (minorRadius < 0)
0352 {
0353 minorRadius = -minorRadius;
0354 }
0355 pos.Scale(theP, theS);
0356 }
0357
0358
0359
0360
0361
0362 inline gp_Elips gp_Elips::Scaled(const gp_Pnt& theP, const double theS) const
0363 {
0364 gp_Elips anE = *this;
0365 anE.majorRadius *= theS;
0366 if (anE.majorRadius < 0)
0367 {
0368 anE.majorRadius = -anE.majorRadius;
0369 }
0370 anE.minorRadius *= theS;
0371 if (anE.minorRadius < 0)
0372 {
0373 anE.minorRadius = -anE.minorRadius;
0374 }
0375 anE.pos.Scale(theP, theS);
0376 return anE;
0377 }
0378
0379
0380
0381 inline void gp_Elips::Transform(const gp_Trsf& theT)
0382 {
0383 majorRadius *= theT.ScaleFactor();
0384 if (majorRadius < 0)
0385 {
0386 majorRadius = -majorRadius;
0387 }
0388 minorRadius *= theT.ScaleFactor();
0389 if (minorRadius < 0)
0390 {
0391 minorRadius = -minorRadius;
0392 }
0393 pos.Transform(theT);
0394 }
0395
0396
0397
0398 inline gp_Elips gp_Elips::Transformed(const gp_Trsf& theT) const
0399 {
0400 gp_Elips anE = *this;
0401 anE.majorRadius *= theT.ScaleFactor();
0402 if (anE.majorRadius < 0)
0403 {
0404 anE.majorRadius = -anE.majorRadius;
0405 }
0406 anE.minorRadius *= theT.ScaleFactor();
0407 if (anE.minorRadius < 0)
0408 {
0409 anE.minorRadius = -anE.minorRadius;
0410 }
0411 anE.pos.Transform(theT);
0412 return anE;
0413 }
0414
0415 #endif