|
||||
File indexing completed on 2025-01-18 10:03:44
0001 // Copyright (c) 1991-1999 Matra Datavision 0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0003 // 0004 // This file is part of Open CASCADE Technology software library. 0005 // 0006 // This library is free software; you can redistribute it and/or modify it under 0007 // the terms of the GNU Lesser General Public License version 2.1 as published 0008 // by the Free Software Foundation, with special exception defined in the file 0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 // distribution for complete text of the license and disclaimer of any warranty. 0011 // 0012 // Alternatively, this file may be used under the terms of Open CASCADE 0013 // commercial license or contractual agreement. 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 //! Describes an ellipse in 3D space. 0025 //! An ellipse is defined by its major and minor radii and 0026 //! positioned in space with a coordinate system (a gp_Ax2 object) as follows: 0027 //! - the origin of the coordinate system is the center of the ellipse, 0028 //! - its "X Direction" defines the major axis of the ellipse, and 0029 //! - its "Y Direction" defines the minor axis of the ellipse. 0030 //! Together, the origin, "X Direction" and "Y Direction" of 0031 //! this coordinate system define the plane of the ellipse. 0032 //! This coordinate system is the "local coordinate system" 0033 //! of the ellipse. In this coordinate system, the equation of 0034 //! the ellipse is: 0035 //! @code 0036 //! X*X / (MajorRadius**2) + Y*Y / (MinorRadius**2) = 1.0 0037 //! @endcode 0038 //! The "main Direction" of the local coordinate system gives 0039 //! the normal vector to the plane of the ellipse. This vector 0040 //! gives an implicit orientation to the ellipse (definition of the 0041 //! trigonometric sense). We refer to the "main Axis" of the 0042 //! local coordinate system as the "Axis" of the ellipse. 0043 //! See Also 0044 //! gce_MakeElips which provides functions for more 0045 //! complex ellipse constructions 0046 //! Geom_Ellipse which provides additional functions for 0047 //! constructing ellipses and works, in particular, with the 0048 //! parametric equations of ellipses 0049 class gp_Elips 0050 { 0051 public: 0052 0053 DEFINE_STANDARD_ALLOC 0054 0055 //! Creates an indefinite ellipse. 0056 gp_Elips() 0057 : majorRadius (RealLast()), 0058 minorRadius (RealSmall()) 0059 {} 0060 0061 //! The major radius of the ellipse is on the "XAxis" and the 0062 //! minor radius is on the "YAxis" of the ellipse. The "XAxis" 0063 //! is defined with the "XDirection" of theA2 and the "YAxis" is 0064 //! defined with the "YDirection" of theA2. 0065 //! Warnings : 0066 //! It is not forbidden to create an ellipse with theMajorRadius = 0067 //! theMinorRadius. 0068 //! Raises ConstructionError if theMajorRadius < theMinorRadius or theMinorRadius < 0. 0069 gp_Elips (const gp_Ax2& theA2, const Standard_Real theMajorRadius, const Standard_Real 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 //! Changes the axis normal to the plane of the ellipse. 0079 //! It modifies the definition of this plane. 0080 //! The "XAxis" and the "YAxis" are recomputed. 0081 //! The local coordinate system is redefined so that: 0082 //! - its origin and "main Direction" become those of the 0083 //! axis theA1 (the "X Direction" and "Y Direction" are then 0084 //! recomputed in the same way as for any gp_Ax2), or 0085 //! Raises ConstructionError if the direction of theA1 0086 //! is parallel to the direction of the "XAxis" of the ellipse. 0087 void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } 0088 0089 //! Modifies this ellipse, by redefining its local coordinate 0090 //! so that its origin becomes theP. 0091 void SetLocation (const gp_Pnt& theP) { pos.SetLocation (theP); } 0092 0093 //! The major radius of the ellipse is on the "XAxis" (major axis) 0094 //! of the ellipse. 0095 //! Raises ConstructionError if theMajorRadius < MinorRadius. 0096 void SetMajorRadius (const Standard_Real theMajorRadius) 0097 { 0098 Standard_ConstructionError_Raise_if (theMajorRadius < minorRadius, 0099 "gp_Elips::SetMajorRadius() - major radius should be greater or equal to minor radius"); 0100 majorRadius = theMajorRadius; 0101 } 0102 0103 //! The minor radius of the ellipse is on the "YAxis" (minor axis) 0104 //! of the ellipse. 0105 //! Raises ConstructionError if theMinorRadius > MajorRadius or MinorRadius < 0. 0106 void SetMinorRadius (const Standard_Real theMinorRadius) 0107 { 0108 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || majorRadius < theMinorRadius, 0109 "gp_Elips::SetMinorRadius() - minor radius should be a positive number lesser or equal to major radius"); 0110 minorRadius = theMinorRadius; 0111 } 0112 0113 //! Modifies this ellipse, by redefining its local coordinate 0114 //! so that it becomes theA2. 0115 void SetPosition (const gp_Ax2& theA2) { pos = theA2; } 0116 0117 //! Computes the area of the Ellipse. 0118 Standard_Real Area() const { return M_PI * majorRadius * minorRadius; } 0119 0120 //! Computes the axis normal to the plane of the ellipse. 0121 const gp_Ax1& Axis() const { return pos.Axis(); } 0122 0123 //! Computes the first or second directrix of this ellipse. 0124 //! These are the lines, in the plane of the ellipse, normal to 0125 //! the major axis, at a distance equal to 0126 //! MajorRadius/e from the center of the ellipse, where 0127 //! e is the eccentricity of the ellipse. 0128 //! The first directrix (Directrix1) is on the positive side of 0129 //! the major axis. The second directrix (Directrix2) is on 0130 //! the negative side. 0131 //! The directrix is returned as an axis (gp_Ax1 object), the 0132 //! origin of which is situated on the "X Axis" of the local 0133 //! coordinate system of this ellipse. 0134 //! Exceptions 0135 //! Standard_ConstructionError if the eccentricity is null 0136 //! (the ellipse has degenerated into a circle). 0137 gp_Ax1 Directrix1() const; 0138 0139 //! This line is obtained by the symmetrical transformation 0140 //! of "Directrix1" with respect to the "YAxis" of the ellipse. 0141 //! Exceptions 0142 //! Standard_ConstructionError if the eccentricity is null 0143 //! (the ellipse has degenerated into a circle). 0144 gp_Ax1 Directrix2() const; 0145 0146 //! Returns the eccentricity of the ellipse between 0.0 and 1.0 0147 //! If f is the distance between the center of the ellipse and 0148 //! the Focus1 then the eccentricity e = f / MajorRadius. 0149 //! Raises ConstructionError if MajorRadius = 0.0 0150 Standard_Real Eccentricity() const; 0151 0152 //! Computes the focal distance. It is the distance between the 0153 //! two focus focus1 and focus2 of the ellipse. 0154 Standard_Real Focal() const 0155 { 0156 return 2.0 * sqrt (majorRadius * majorRadius - minorRadius * minorRadius); 0157 } 0158 0159 //! Returns the first focus of the ellipse. This focus is on the 0160 //! positive side of the "XAxis" of the ellipse. 0161 gp_Pnt Focus1() const; 0162 0163 //! Returns the second focus of the ellipse. This focus is on the 0164 //! negative side of the "XAxis" of the ellipse. 0165 gp_Pnt Focus2() const; 0166 0167 //! Returns the center of the ellipse. It is the "Location" 0168 //! point of the coordinate system of the ellipse. 0169 const gp_Pnt& Location() const { return pos.Location(); } 0170 0171 //! Returns the major radius of the ellipse. 0172 Standard_Real MajorRadius() const { return majorRadius; } 0173 0174 //! Returns the minor radius of the ellipse. 0175 Standard_Real MinorRadius() const { return minorRadius; } 0176 0177 //! Returns p = (1 - e * e) * MajorRadius where e is the eccentricity 0178 //! of the ellipse. 0179 //! Returns 0 if MajorRadius = 0 0180 Standard_Real Parameter() const; 0181 0182 //! Returns the coordinate system of the ellipse. 0183 const gp_Ax2& Position() const { return pos; } 0184 0185 //! Returns the "XAxis" of the ellipse whose origin 0186 //! is the center of this ellipse. It is the major axis of the 0187 //! ellipse. 0188 gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } 0189 0190 //! Returns the "YAxis" of the ellipse whose unit vector is the "X Direction" or the "Y Direction" 0191 //! of the local coordinate system of this ellipse. 0192 //! This is the minor axis of the ellipse. 0193 gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } 0194 0195 Standard_EXPORT void Mirror (const gp_Pnt& theP); 0196 0197 //! Performs the symmetrical transformation of an ellipse with 0198 //! respect to the point theP which is the center of the symmetry. 0199 Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Pnt& theP) const; 0200 0201 Standard_EXPORT void Mirror (const gp_Ax1& theA1); 0202 0203 //! Performs the symmetrical transformation of an ellipse with 0204 //! respect to an axis placement which is the axis of the symmetry. 0205 Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Ax1& theA1) const; 0206 0207 Standard_EXPORT void Mirror (const gp_Ax2& theA2); 0208 0209 //! Performs the symmetrical transformation of an ellipse with 0210 //! respect to a plane. The axis placement theA2 locates the plane 0211 //! of the symmetry (Location, XDirection, YDirection). 0212 Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Ax2& theA2) const; 0213 0214 void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } 0215 0216 //! Rotates an ellipse. theA1 is the axis of the rotation. 0217 //! theAng is the angular value of the rotation in radians. 0218 Standard_NODISCARD gp_Elips Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const 0219 { 0220 gp_Elips anE = *this; 0221 anE.pos.Rotate (theA1, theAng); 0222 return anE; 0223 } 0224 0225 void Scale (const gp_Pnt& theP, const Standard_Real theS); 0226 0227 //! Scales an ellipse. theS is the scaling value. 0228 Standard_NODISCARD gp_Elips Scaled (const gp_Pnt& theP, const Standard_Real theS) const; 0229 0230 void Transform (const gp_Trsf& theT); 0231 0232 //! Transforms an ellipse with the transformation theT from class Trsf. 0233 Standard_NODISCARD gp_Elips Transformed (const gp_Trsf& theT) const; 0234 0235 void Translate (const gp_Vec& theV) { pos.Translate (theV); } 0236 0237 //! Translates an ellipse in the direction of the vector theV. 0238 //! The magnitude of the translation is the vector's magnitude. 0239 Standard_NODISCARD gp_Elips Translated (const gp_Vec& theV) const 0240 { 0241 gp_Elips anE = *this; 0242 anE.pos.Translate (theV); 0243 return anE; 0244 } 0245 0246 void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } 0247 0248 //! Translates an ellipse from the point theP1 to the point theP2. 0249 Standard_NODISCARD gp_Elips Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const 0250 { 0251 gp_Elips anE = *this; 0252 anE.pos.Translate (theP1, theP2); 0253 return anE; 0254 } 0255 0256 private: 0257 0258 gp_Ax2 pos; 0259 Standard_Real majorRadius; 0260 Standard_Real minorRadius; 0261 0262 }; 0263 0264 // ======================================================================= 0265 // function : Directrix1 0266 // purpose : 0267 // ======================================================================= 0268 inline gp_Ax1 gp_Elips::Directrix1() const 0269 { 0270 Standard_Real anE = Eccentricity(); 0271 Standard_ConstructionError_Raise_if (anE <= gp::Resolution(), "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 // function : Directrix2 0280 // purpose : 0281 // ======================================================================= 0282 inline gp_Ax1 gp_Elips::Directrix2() const 0283 { 0284 Standard_Real anE = Eccentricity(); 0285 Standard_ConstructionError_Raise_if (anE <= gp::Resolution(), "gp_Elips::Directrix2() - zero eccentricity"); 0286 gp_XYZ anOrig = pos.XDirection().XYZ(); 0287 anOrig.Multiply (-majorRadius / anE); 0288 anOrig.Add (pos.Location().XYZ()); 0289 return gp_Ax1 (gp_Pnt (anOrig), pos.YDirection()); 0290 } 0291 0292 // ======================================================================= 0293 // function : Eccentricity 0294 // purpose : 0295 // ======================================================================= 0296 inline Standard_Real gp_Elips::Eccentricity() const 0297 { 0298 if (majorRadius == 0.0) 0299 { 0300 return 0.0; 0301 } 0302 else 0303 { 0304 return sqrt (majorRadius * majorRadius - minorRadius * minorRadius) / majorRadius; 0305 } 0306 } 0307 0308 // ======================================================================= 0309 // function : Focus1 0310 // purpose : 0311 // ======================================================================= 0312 inline gp_Pnt gp_Elips::Focus1() const 0313 { 0314 Standard_Real aC = sqrt (majorRadius * majorRadius - minorRadius * minorRadius); 0315 const gp_Pnt& aPP = pos.Location(); 0316 const gp_Dir& aDD = pos.XDirection(); 0317 return gp_Pnt (aPP.X() + aC * aDD.X(), 0318 aPP.Y() + aC * aDD.Y(), 0319 aPP.Z() + aC * aDD.Z()); 0320 } 0321 0322 // ======================================================================= 0323 // function : Focus2 0324 // purpose : 0325 // ======================================================================= 0326 inline gp_Pnt gp_Elips::Focus2() const 0327 { 0328 Standard_Real aC = sqrt (majorRadius * majorRadius - minorRadius * minorRadius); 0329 const gp_Pnt& aPP = pos.Location(); 0330 const gp_Dir& aDD = pos.XDirection(); 0331 return gp_Pnt (aPP.X() - aC * aDD.X(), 0332 aPP.Y() - aC * aDD.Y(), 0333 aPP.Z() - aC * aDD.Z()); 0334 } 0335 0336 // ======================================================================= 0337 // function : Parameter 0338 // purpose : 0339 // ======================================================================= 0340 inline Standard_Real gp_Elips::Parameter() const 0341 { 0342 if (majorRadius == 0.0) 0343 { 0344 return 0.0; 0345 } 0346 else 0347 { 0348 return (minorRadius * minorRadius) / majorRadius; 0349 } 0350 } 0351 0352 // ======================================================================= 0353 // function : Scale 0354 // purpose : 0355 // ======================================================================= 0356 inline void gp_Elips::Scale (const gp_Pnt& theP, 0357 const Standard_Real theS) 0358 // Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 Begin 0359 // { pos.Scale(P, S); } 0360 { 0361 majorRadius *= theS; 0362 if (majorRadius < 0) 0363 { 0364 majorRadius = -majorRadius; 0365 } 0366 minorRadius *= theS; 0367 if (minorRadius < 0) 0368 { 0369 minorRadius = -minorRadius; 0370 } 0371 pos.Scale (theP, theS); 0372 } 0373 // Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 End 0374 0375 // ======================================================================= 0376 // function : Scaled 0377 // purpose : 0378 // ======================================================================= 0379 inline gp_Elips gp_Elips::Scaled (const gp_Pnt& theP, 0380 const Standard_Real theS) const 0381 { 0382 gp_Elips anE = *this; 0383 anE.majorRadius *= theS; 0384 if (anE.majorRadius < 0) 0385 { 0386 anE.majorRadius = -anE.majorRadius; 0387 } 0388 anE.minorRadius *= theS; 0389 if (anE.minorRadius < 0) 0390 { 0391 anE.minorRadius = -anE.minorRadius; 0392 } 0393 anE.pos.Scale (theP, theS); 0394 return anE; 0395 } 0396 0397 // ======================================================================= 0398 // function : Transform 0399 // purpose : 0400 // ======================================================================= 0401 inline void gp_Elips::Transform (const gp_Trsf& theT) 0402 { 0403 majorRadius *= theT.ScaleFactor(); 0404 if (majorRadius < 0) 0405 { 0406 majorRadius = -majorRadius; 0407 } 0408 minorRadius *= theT.ScaleFactor(); 0409 if (minorRadius < 0) 0410 { 0411 minorRadius = -minorRadius; 0412 } 0413 pos.Transform (theT); 0414 } 0415 0416 // ======================================================================= 0417 // function : Transformed 0418 // purpose : 0419 // ======================================================================= 0420 inline gp_Elips gp_Elips::Transformed (const gp_Trsf& theT) const 0421 { 0422 gp_Elips anE = *this; 0423 anE.majorRadius *= theT.ScaleFactor(); 0424 if (anE.majorRadius < 0) 0425 { 0426 anE.majorRadius = -anE.majorRadius; 0427 } 0428 anE.minorRadius *= theT.ScaleFactor(); 0429 if (anE.minorRadius < 0) 0430 { 0431 anE.minorRadius = -anE.minorRadius; 0432 } 0433 anE.pos.Transform (theT); 0434 return anE; 0435 } 0436 0437 #endif // _gp_Elips_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |