|
|
|||
Warning, file /include/opencascade/gp_Torus.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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_Torus_HeaderFile 0016 #define _gp_Torus_HeaderFile 0017 0018 #include <gp_Ax1.hxx> 0019 #include <gp_Ax3.hxx> 0020 #include <Standard_ConstructionError.hxx> 0021 #include <TColStd_Array1OfReal.hxx> 0022 0023 //! Describes a torus. 0024 //! A torus is defined by its major and minor radii and 0025 //! positioned in space with a coordinate system (a gp_Ax3 0026 //! object) as follows: 0027 //! - The origin of the coordinate system is the center of the torus; 0028 //! - The surface is obtained by rotating a circle of radius 0029 //! equal to the minor radius of the torus about the "main 0030 //! Direction" of the coordinate system. This circle is 0031 //! located in the plane defined by the origin, the "X 0032 //! Direction" and the "main Direction" of the coordinate 0033 //! system. It is centered on the "X Axis" of this coordinate 0034 //! system, and located at a distance, from the origin of 0035 //! this coordinate system, equal to the major radius of the torus; 0036 //! - The "X Direction" and "Y Direction" define the 0037 //! reference plane of the torus. 0038 //! The coordinate system described above is the "local 0039 //! coordinate system" of the torus. 0040 //! Note: when a gp_Torus torus is converted into a 0041 //! Geom_ToroidalSurface torus, some implicit properties 0042 //! of its local coordinate system are used explicitly: 0043 //! - its origin, "X Direction", "Y Direction" and "main 0044 //! Direction" are used directly to define the parametric 0045 //! directions on the torus and the origin of the parameters, 0046 //! - its implicit orientation (right-handed or left-handed) 0047 //! gives the orientation (direct, indirect) to the 0048 //! Geom_ToroidalSurface torus. 0049 //! See Also 0050 //! gce_MakeTorus which provides functions for more 0051 //! complex torus constructions 0052 //! Geom_ToroidalSurface which provides additional 0053 //! functions for constructing tori and works, in particular, 0054 //! with the parametric equations of tori. 0055 class gp_Torus 0056 { 0057 public: 0058 0059 DEFINE_STANDARD_ALLOC 0060 0061 //! creates an indefinite Torus. 0062 gp_Torus() 0063 : majorRadius (RealLast()), 0064 minorRadius (RealSmall()) 0065 {} 0066 0067 //! a torus centered on the origin of coordinate system 0068 //! theA3, with major radius theMajorRadius and minor radius 0069 //! theMinorRadius, and with the reference plane defined 0070 //! by the origin, the "X Direction" and the "Y Direction" of theA3. 0071 //! Warnings : 0072 //! It is not forbidden to create a torus with 0073 //! theMajorRadius = theMinorRadius = 0.0 0074 //! Raises ConstructionError if theMinorRadius < 0.0 or if theMajorRadius < 0.0 0075 gp_Torus (const gp_Ax3& theA3, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius) 0076 : pos (theA3), 0077 majorRadius (theMajorRadius), 0078 minorRadius (theMinorRadius) 0079 { 0080 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0, 0081 "gp_Torus() - invalid construction parameters"); 0082 } 0083 0084 //! Modifies this torus, by redefining its local coordinate 0085 //! system so that: 0086 //! - its origin and "main Direction" become those of the 0087 //! axis theA1 (the "X Direction" and "Y Direction" are then recomputed). 0088 //! Raises ConstructionError if the direction of theA1 is parallel to the "XDirection" 0089 //! of the coordinate system of the toroidal surface. 0090 void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } 0091 0092 //! Changes the location of the torus. 0093 void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); } 0094 0095 //! Assigns value to the major radius of this torus. 0096 //! Raises ConstructionError if theMajorRadius - MinorRadius <= Resolution() 0097 void SetMajorRadius (const Standard_Real theMajorRadius) 0098 { 0099 Standard_ConstructionError_Raise_if (theMajorRadius - minorRadius <= gp::Resolution(), 0100 "gp_Torus::SetMajorRadius() - invalid input parameters"); 0101 majorRadius = theMajorRadius; 0102 } 0103 0104 //! Assigns value to the minor radius of this torus. 0105 //! Raises ConstructionError if theMinorRadius < 0.0 or if 0106 //! MajorRadius - theMinorRadius <= Resolution from gp. 0107 void SetMinorRadius (const Standard_Real theMinorRadius) 0108 { 0109 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || majorRadius - theMinorRadius <= gp::Resolution(), 0110 "gp_Torus::SetMinorRadius() - invalid input parameters"); 0111 minorRadius = theMinorRadius; 0112 } 0113 0114 //! Changes the local coordinate system of the surface. 0115 void SetPosition (const gp_Ax3& theA3) { pos = theA3; } 0116 0117 //! Computes the area of the torus. 0118 Standard_Real Area() const { return 4.0 * M_PI * M_PI * minorRadius * majorRadius; } 0119 0120 //! Reverses the U parametrization of the torus 0121 //! reversing the YAxis. 0122 void UReverse() { pos.YReverse(); } 0123 0124 //! Reverses the V parametrization of the torus 0125 //! reversing the ZAxis. 0126 void VReverse() { pos.ZReverse(); } 0127 0128 //! returns true if the Ax3, the local coordinate system of this torus, is right handed. 0129 Standard_Boolean Direct() const { return pos.Direct(); } 0130 0131 //! returns the symmetry axis of the torus. 0132 const gp_Ax1& Axis() const { return pos.Axis(); } 0133 0134 //! Computes the coefficients of the implicit equation of the surface 0135 //! in the absolute Cartesian coordinate system: 0136 //! @code 0137 //! Coef(1) * X^4 + Coef(2) * Y^4 + Coef(3) * Z^4 + 0138 //! Coef(4) * X^3 * Y + Coef(5) * X^3 * Z + Coef(6) * Y^3 * X + 0139 //! Coef(7) * Y^3 * Z + Coef(8) * Z^3 * X + Coef(9) * Z^3 * Y + 0140 //! Coef(10) * X^2 * Y^2 + Coef(11) * X^2 * Z^2 + 0141 //! Coef(12) * Y^2 * Z^2 + Coef(13) * X^2 * Y * Z + 0142 //! Coef(14) * X * Y^2 * Z + Coef(15) * X * Y * Z^2 + 0143 //! Coef(16) * X^3 + Coef(17) * Y^3 + Coef(18) * Z^3 + 0144 //! Coef(19) * X^2 * Y + Coef(20) * X^2 * Z + Coef(21) * Y^2 * X + 0145 //! Coef(22) * Y^2 * Z + Coef(23) * Z^2 * X + Coef(24) * Z^2 * Y + 0146 //! Coef(25) * X * Y * Z + 0147 //! Coef(26) * X^2 + Coef(27) * Y^2 + Coef(28) * Z^2 + 0148 //! Coef(29) * X * Y + Coef(30) * X * Z + Coef(31) * Y * Z + 0149 //! Coef(32) * X + Coef(33) * Y + Coef(34) * Z + 0150 //! Coef(35) = 0.0 0151 //! @endcode 0152 //! Raises DimensionError if the length of theCoef is lower than 35. 0153 Standard_EXPORT void Coefficients (TColStd_Array1OfReal& theCoef) const; 0154 0155 //! Returns the Torus's location. 0156 const gp_Pnt& Location() const { return pos.Location(); } 0157 0158 //! Returns the local coordinates system of the torus. 0159 const gp_Ax3& Position() const { return pos; } 0160 0161 //! returns the major radius of the torus. 0162 Standard_Real MajorRadius() const { return majorRadius; } 0163 0164 //! returns the minor radius of the torus. 0165 Standard_Real MinorRadius() const { return minorRadius; } 0166 0167 //! Computes the volume of the torus. 0168 Standard_Real Volume() const 0169 { 0170 return (M_PI * minorRadius * minorRadius) * (2.0 * M_PI * majorRadius); 0171 } 0172 0173 //! returns the axis X of the torus. 0174 gp_Ax1 XAxis() const 0175 { 0176 return gp_Ax1 (pos.Location(), pos.XDirection()); 0177 } 0178 0179 //! returns the axis Y of the torus. 0180 gp_Ax1 YAxis() const 0181 { 0182 return gp_Ax1 (pos.Location(), pos.YDirection()); 0183 } 0184 0185 Standard_EXPORT void Mirror (const gp_Pnt& theP); 0186 0187 //! Performs the symmetrical transformation of a torus 0188 //! with respect to the point theP which is the center of the 0189 //! symmetry. 0190 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Pnt& theP) const; 0191 0192 Standard_EXPORT void Mirror (const gp_Ax1& theA1); 0193 0194 //! Performs the symmetrical transformation of a torus with 0195 //! respect to an axis placement which is the axis of the 0196 //! symmetry. 0197 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax1& theA1) const; 0198 0199 Standard_EXPORT void Mirror (const gp_Ax2& theA2); 0200 0201 //! Performs the symmetrical transformation of a torus with respect 0202 //! to a plane. The axis placement theA2 locates the plane of the 0203 //! of the symmetry : (Location, XDirection, YDirection). 0204 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax2& theA2) const; 0205 0206 void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } 0207 0208 //! Rotates a torus. theA1 is the axis of the rotation. 0209 //! theAng is the angular value of the rotation in radians. 0210 Standard_NODISCARD gp_Torus Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const 0211 { 0212 gp_Torus aC = *this; 0213 aC.pos.Rotate (theA1, theAng); 0214 return aC; 0215 } 0216 0217 void Scale (const gp_Pnt& theP, const Standard_Real theS); 0218 0219 //! Scales a torus. S is the scaling value. 0220 //! The absolute value of S is used to scale the torus 0221 Standard_NODISCARD gp_Torus Scaled (const gp_Pnt& theP, const Standard_Real theS) const; 0222 0223 void Transform (const gp_Trsf& theT); 0224 0225 //! Transforms a torus with the transformation theT from class Trsf. 0226 Standard_NODISCARD gp_Torus Transformed (const gp_Trsf& theT) const; 0227 0228 void Translate (const gp_Vec& theV) { pos.Translate (theV); } 0229 0230 //! Translates a torus in the direction of the vector theV. 0231 //! The magnitude of the translation is the vector's magnitude. 0232 Standard_NODISCARD gp_Torus Translated (const gp_Vec& theV) const 0233 { 0234 gp_Torus aC = *this; 0235 aC.pos.Translate (theV); 0236 return aC; 0237 } 0238 0239 void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } 0240 0241 //! Translates a torus from the point theP1 to the point theP2. 0242 Standard_NODISCARD gp_Torus Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const 0243 { 0244 gp_Torus aC = *this; 0245 aC.pos.Translate (theP1, theP2); 0246 return aC; 0247 } 0248 0249 private: 0250 0251 gp_Ax3 pos; 0252 Standard_Real majorRadius; 0253 Standard_Real minorRadius; 0254 0255 }; 0256 0257 //======================================================================= 0258 //function : Scale 0259 // purpose : 0260 //======================================================================= 0261 inline void gp_Torus::Scale (const gp_Pnt& theP, 0262 const Standard_Real theS) 0263 { 0264 pos.Scale (theP, theS); 0265 Standard_Real s = theS; 0266 if (s < 0) 0267 { 0268 s = -s; 0269 } 0270 majorRadius *= s; 0271 minorRadius *= s; 0272 } 0273 0274 //======================================================================= 0275 //function : Scaled 0276 // purpose : 0277 //======================================================================= 0278 inline gp_Torus gp_Torus::Scaled (const gp_Pnt& theP, 0279 const Standard_Real theS) const 0280 { 0281 gp_Torus aC = *this; 0282 aC.pos.Scale (theP, theS); 0283 aC.majorRadius *= theS; 0284 if (aC.majorRadius < 0) 0285 { 0286 aC.majorRadius = -aC.majorRadius; 0287 } 0288 aC.minorRadius *= theS; 0289 if (aC.minorRadius < 0) 0290 { 0291 aC.minorRadius = -aC.minorRadius; 0292 } 0293 return aC; 0294 } 0295 0296 //======================================================================= 0297 //function : Transform 0298 // purpose : 0299 //======================================================================= 0300 inline void gp_Torus::Transform (const gp_Trsf& theT) 0301 { 0302 pos.Transform (theT); 0303 Standard_Real aT = theT.ScaleFactor(); 0304 if (aT < 0) 0305 { 0306 aT = -aT; 0307 } 0308 minorRadius *= aT; 0309 majorRadius *= aT; 0310 } 0311 0312 //======================================================================= 0313 //function : Transformed 0314 // purpose : 0315 //======================================================================= 0316 inline gp_Torus gp_Torus::Transformed (const gp_Trsf& theT) const 0317 { 0318 gp_Torus aC = *this; 0319 aC.pos.Transform (theT); 0320 aC.majorRadius *= theT.ScaleFactor(); 0321 if (aC.majorRadius < 0) 0322 { 0323 aC.majorRadius = -aC.majorRadius; 0324 } 0325 aC.minorRadius *= theT.ScaleFactor(); 0326 if (aC.minorRadius < 0) 0327 { 0328 aC.minorRadius = -aC.minorRadius; 0329 } 0330 return aC; 0331 } 0332 0333 #endif // _gp_Torus_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|