File indexing completed on 2025-01-18 10:03:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_Circ2d_HeaderFile
0016 #define _gp_Circ2d_HeaderFile
0017
0018 #include <gp_Ax22d.hxx>
0019 #include <gp_Ax2d.hxx>
0020 #include <gp_Pnt2d.hxx>
0021 #include <gp_Trsf2d.hxx>
0022 #include <gp_Vec2d.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 class gp_Circ2d
0050 {
0051 public:
0052
0053 DEFINE_STANDARD_ALLOC
0054
0055
0056 gp_Circ2d()
0057 : radius (RealLast())
0058 {}
0059
0060
0061
0062
0063
0064 gp_Circ2d (const gp_Ax2d& theXAxis, const Standard_Real theRadius, const Standard_Boolean theIsSense = Standard_True)
0065 : radius (theRadius)
0066 {
0067 Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d() - radius should be positive number");
0068 pos = gp_Ax22d (theXAxis, theIsSense);
0069 }
0070
0071
0072
0073
0074
0075
0076
0077 gp_Circ2d (const gp_Ax22d& theAxis, const Standard_Real theRadius)
0078 : pos (theAxis),
0079 radius (theRadius)
0080 {
0081 Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d() - radius should be positive number");
0082 }
0083
0084
0085 void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); }
0086
0087
0088 void SetXAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); }
0089
0090
0091 void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); }
0092
0093
0094 void SetYAxis (const gp_Ax2d& theA) { pos.SetYAxis (theA); }
0095
0096
0097
0098
0099
0100
0101 void SetRadius (const Standard_Real theRadius)
0102 {
0103 Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d::SetRadius() - radius should be positive number");
0104 radius = theRadius;
0105 }
0106
0107
0108 Standard_Real Area() const { return M_PI * radius * radius; }
0109
0110
0111
0112
0113 void Coefficients (Standard_Real& theA, Standard_Real& theB,
0114 Standard_Real& theC, Standard_Real& theD,
0115 Standard_Real& theE, Standard_Real& theF) const;
0116
0117
0118
0119
0120
0121 Standard_Boolean Contains (const gp_Pnt2d& theP, const Standard_Real theLinearTolerance) const
0122 {
0123 return Distance (theP) <= theLinearTolerance;
0124 }
0125
0126
0127
0128 Standard_Real Distance (const gp_Pnt2d& theP) const;
0129
0130
0131 Standard_Real SquareDistance (const gp_Pnt2d& theP) const;
0132
0133
0134 Standard_Real Length() const { return 2. * M_PI * radius; }
0135
0136
0137 const gp_Pnt2d& Location() const { return pos.Location(); }
0138
0139
0140 Standard_Real Radius() const { return radius; }
0141
0142
0143 const gp_Ax22d& Axis() const { return pos; }
0144
0145
0146 const gp_Ax22d& Position() const { return pos; }
0147
0148
0149 gp_Ax2d XAxis() const { return gp_Ax2d (pos.XAxis()); }
0150
0151
0152
0153 gp_Ax2d YAxis() const { return gp_Ax2d (pos.YAxis()); }
0154
0155
0156
0157
0158
0159 void Reverse()
0160 {
0161 gp_Dir2d aTemp = pos.YDirection();
0162 aTemp.Reverse();
0163 pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp));
0164 }
0165
0166
0167
0168
0169
0170 Standard_NODISCARD gp_Circ2d Reversed() const;
0171
0172
0173
0174 Standard_Boolean IsDirect() const
0175 {
0176 return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0;
0177 }
0178
0179 Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
0180
0181
0182
0183 Standard_NODISCARD Standard_EXPORT gp_Circ2d Mirrored (const gp_Pnt2d& theP) const;
0184
0185 Standard_EXPORT void Mirror (const gp_Ax2d& theA);
0186
0187
0188
0189 Standard_NODISCARD Standard_EXPORT gp_Circ2d Mirrored (const gp_Ax2d& theA) const;
0190
0191 void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
0192 {
0193 pos.Rotate (theP, theAng);
0194 }
0195
0196
0197
0198 Standard_NODISCARD gp_Circ2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
0199 {
0200 gp_Circ2d aCirc = *this;
0201 aCirc.pos.Rotate (theP, theAng);
0202 return aCirc;
0203 }
0204
0205 void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
0206
0207
0208
0209
0210
0211
0212 Standard_NODISCARD gp_Circ2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const;
0213
0214 void Transform (const gp_Trsf2d& theT);
0215
0216
0217 Standard_NODISCARD gp_Circ2d Transformed (const gp_Trsf2d& theT) const;
0218
0219 void Translate (const gp_Vec2d& theV) { pos.Translate (theV); }
0220
0221
0222
0223 Standard_NODISCARD gp_Circ2d Translated (const gp_Vec2d& theV) const
0224 {
0225 gp_Circ2d aCirc = *this;
0226 aCirc.pos.Translate (theV);
0227 return aCirc;
0228 }
0229
0230 void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); }
0231
0232
0233 Standard_NODISCARD gp_Circ2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
0234 {
0235 gp_Circ2d aCirc = *this;
0236 aCirc.pos.Translate (theP1, theP2);
0237 return aCirc;
0238 }
0239
0240 private:
0241
0242 gp_Ax22d pos;
0243 Standard_Real radius;
0244
0245 };
0246
0247
0248
0249
0250
0251 inline void gp_Circ2d::Coefficients (Standard_Real& theA,
0252 Standard_Real& theB,
0253 Standard_Real& theC,
0254 Standard_Real& theD,
0255 Standard_Real& theE,
0256 Standard_Real& theF) const
0257 {
0258 Standard_Real aXc = pos.Location().X();
0259 Standard_Real anYc = pos.Location().Y();
0260 theA = 1.0;
0261 theB = 1.0;
0262 theC = 0.0;
0263 theD = - aXc;
0264 theE = - anYc;
0265 theF = aXc * aXc + anYc * anYc - radius * radius;
0266 }
0267
0268
0269
0270
0271
0272 inline Standard_Real gp_Circ2d::Distance (const gp_Pnt2d& theP) const
0273 {
0274 gp_XY aCoord = theP.XY();
0275 aCoord.Subtract (pos.Location().XY());
0276 Standard_Real aD = radius - aCoord.Modulus();
0277 if (aD < 0)
0278 {
0279 aD = -aD;
0280 }
0281 return aD;
0282 }
0283
0284
0285
0286
0287
0288 inline gp_Circ2d gp_Circ2d::Reversed() const
0289 {
0290 gp_Circ2d aCirc = *this;
0291 gp_Dir2d aTemp = pos.YDirection();
0292 aTemp.Reverse();
0293 aCirc.pos.SetAxis (gp_Ax22d(pos.Location(), pos.XDirection(), aTemp));
0294 return aCirc;
0295 }
0296
0297
0298
0299
0300
0301 inline Standard_Real gp_Circ2d::SquareDistance (const gp_Pnt2d& theP) const
0302 {
0303 gp_XY aCoord = theP.XY();
0304 aCoord.Subtract (pos.Location().XY());
0305 Standard_Real aD = radius - aCoord.Modulus();
0306 return aD * aD;
0307 }
0308
0309
0310
0311
0312
0313 inline void gp_Circ2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
0314 {
0315 radius *= theS;
0316 if (radius < 0)
0317 {
0318 radius = -radius;
0319 }
0320 pos.Scale (theP, theS);
0321 }
0322
0323
0324
0325
0326
0327 inline gp_Circ2d gp_Circ2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
0328 {
0329 gp_Circ2d aCirc = *this;
0330 aCirc.radius *= theS;
0331 if (aCirc.radius < 0)
0332 {
0333 aCirc.radius = -aCirc.radius;
0334 }
0335 aCirc.pos.Scale (theP, theS);
0336 return aCirc;
0337 }
0338
0339
0340
0341
0342
0343 inline void gp_Circ2d::Transform (const gp_Trsf2d& theT)
0344 {
0345 radius *= theT.ScaleFactor();
0346 if (radius < 0)
0347 {
0348 radius = -radius;
0349 }
0350 pos.Transform (theT);
0351 }
0352
0353
0354
0355
0356
0357 inline gp_Circ2d gp_Circ2d::Transformed (const gp_Trsf2d& theT) const
0358 {
0359 gp_Circ2d aCirc = *this;
0360 aCirc.radius *= theT.ScaleFactor();
0361 if (aCirc.radius < 0)
0362 {
0363 aCirc.radius = -aCirc.radius;
0364 }
0365 aCirc.pos.Transform (theT);
0366 return aCirc;
0367 }
0368
0369 #endif