1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _gp_Torus_HeaderFile
16 #define _gp_Torus_HeaderFile
20 #include <Standard_ConstructionError.hxx>
21 #include <Standard_DimensionError.hxx>
22 #include <TColStd_Array1OfReal.hxx>
24 //! Describes a torus.
25 //! A torus is defined by its major and minor radii and
26 //! positioned in space with a coordinate system (a gp_Ax3
27 //! object) as follows:
28 //! - The origin of the coordinate system is the center of the torus;
29 //! - The surface is obtained by rotating a circle of radius
30 //! equal to the minor radius of the torus about the "main
31 //! Direction" of the coordinate system. This circle is
32 //! located in the plane defined by the origin, the "X
33 //! Direction" and the "main Direction" of the coordinate
34 //! system. It is centered on the "X Axis" of this coordinate
35 //! system, and located at a distance, from the origin of
36 //! this coordinate system, equal to the major radius of the torus;
37 //! - The "X Direction" and "Y Direction" define the
38 //! reference plane of the torus.
39 //! The coordinate system described above is the "local
40 //! coordinate system" of the torus.
41 //! Note: when a gp_Torus torus is converted into a
42 //! Geom_ToroidalSurface torus, some implicit properties
43 //! of its local coordinate system are used explicitly:
44 //! - its origin, "X Direction", "Y Direction" and "main
45 //! Direction" are used directly to define the parametric
46 //! directions on the torus and the origin of the parameters,
47 //! - its implicit orientation (right-handed or left-handed)
48 //! gives the orientation (direct, indirect) to the
49 //! Geom_ToroidalSurface torus.
51 //! gce_MakeTorus which provides functions for more
52 //! complex torus constructions
53 //! Geom_ToroidalSurface which provides additional
54 //! functions for constructing tori and works, in particular,
55 //! with the parametric equations of tori.
62 //! creates an indefinite Torus.
64 : majorRadius (RealLast()),
65 minorRadius (RealSmall())
68 //! a torus centered on the origin of coordinate system
69 //! theA3, with major radius theMajorRadius and minor radius
70 //! theMinorRadius, and with the reference plane defined
71 //! by the origin, the "X Direction" and the "Y Direction" of theA3.
73 //! It is not forbidden to create a torus with
74 //! theMajorRadius = theMinorRadius = 0.0
75 //! Raises ConstructionError if theMinorRadius < 0.0 or if theMajorRadius < 0.0
76 gp_Torus (const gp_Ax3& theA3, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius)
78 majorRadius (theMajorRadius),
79 minorRadius (theMinorRadius)
81 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0,
82 "gp_Torus() - invalid construction parameters");
85 //! Modifies this torus, by redefining its local coordinate
87 //! - its origin and "main Direction" become those of the
88 //! axis theA1 (the "X Direction" and "Y Direction" are then recomputed).
89 //! Raises ConstructionError if the direction of theA1 is parallel to the "XDirection"
90 //! of the coordinate system of the toroidal surface.
91 void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); }
93 //! Changes the location of the torus.
94 void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); }
96 //! Assigns value to the major radius of this torus.
97 //! Raises ConstructionError if theMajorRadius - MinorRadius <= Resolution()
98 void SetMajorRadius (const Standard_Real theMajorRadius)
100 Standard_ConstructionError_Raise_if (theMajorRadius - minorRadius <= gp::Resolution(),
101 "gp_Torus::SetMajorRadius() - invalid input parameters");
102 majorRadius = theMajorRadius;
105 //! Assigns value to the minor radius of this torus.
106 //! Raises ConstructionError if theMinorRadius < 0.0 or if
107 //! MajorRadius - theMinorRadius <= Resolution from gp.
108 void SetMinorRadius (const Standard_Real theMinorRadius)
110 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || majorRadius - theMinorRadius <= gp::Resolution(),
111 "gp_Torus::SetMinorRadius() - invalid input parameters");
112 minorRadius = theMinorRadius;
115 //! Changes the local coordinate system of the surface.
116 void SetPosition (const gp_Ax3& theA3) { pos = theA3; }
118 //! Computes the area of the torus.
119 Standard_Real Area() const { return 4.0 * M_PI * M_PI * minorRadius * majorRadius; }
121 //! Reverses the U parametrization of the torus
122 //! reversing the YAxis.
123 void UReverse() { pos.YReverse(); }
125 //! Reverses the V parametrization of the torus
126 //! reversing the ZAxis.
127 void VReverse() { pos.ZReverse(); }
129 //! returns true if the Ax3, the local coordinate system of this torus, is right handed.
130 Standard_Boolean Direct() const { return pos.Direct(); }
132 //! returns the symmetry axis of the torus.
133 const gp_Ax1& Axis() const { return pos.Axis(); }
135 //! Computes the coefficients of the implicit equation of the surface
136 //! in the absolute Cartesian coordinate system:
138 //! Coef(1) * X^4 + Coef(2) * Y^4 + Coef(3) * Z^4 +
139 //! Coef(4) * X^3 * Y + Coef(5) * X^3 * Z + Coef(6) * Y^3 * X +
140 //! Coef(7) * Y^3 * Z + Coef(8) * Z^3 * X + Coef(9) * Z^3 * Y +
141 //! Coef(10) * X^2 * Y^2 + Coef(11) * X^2 * Z^2 +
142 //! Coef(12) * Y^2 * Z^2 + Coef(13) * X^2 * Y * Z +
143 //! Coef(14) * X * Y^2 * Z + Coef(15) * X * Y * Z^2 +
144 //! Coef(16) * X^3 + Coef(17) * Y^3 + Coef(18) * Z^3 +
145 //! Coef(19) * X^2 * Y + Coef(20) * X^2 * Z + Coef(21) * Y^2 * X +
146 //! Coef(22) * Y^2 * Z + Coef(23) * Z^2 * X + Coef(24) * Z^2 * Y +
147 //! Coef(25) * X * Y * Z +
148 //! Coef(26) * X^2 + Coef(27) * Y^2 + Coef(28) * Z^2 +
149 //! Coef(29) * X * Y + Coef(30) * X * Z + Coef(31) * Y * Z +
150 //! Coef(32) * X + Coef(33) * Y + Coef(34) * Z +
153 //! Raises DimensionError if the length of theCoef is lower than 35.
154 Standard_EXPORT void Coefficients (TColStd_Array1OfReal& theCoef) const;
156 //! Returns the Torus's location.
157 const gp_Pnt& Location() const { return pos.Location(); }
159 //! Returns the local coordinates system of the torus.
160 const gp_Ax3& Position() const { return pos; }
162 //! returns the major radius of the torus.
163 Standard_Real MajorRadius() const { return majorRadius; }
165 //! returns the minor radius of the torus.
166 Standard_Real MinorRadius() const { return minorRadius; }
168 //! Computes the volume of the torus.
169 Standard_Real Volume() const
171 return (M_PI * minorRadius * minorRadius) * (2.0 * M_PI * majorRadius);
174 //! returns the axis X of the torus.
177 return gp_Ax1 (pos.Location(), pos.XDirection());
180 //! returns the axis Y of the torus.
183 return gp_Ax1 (pos.Location(), pos.YDirection());
186 Standard_EXPORT void Mirror (const gp_Pnt& theP);
188 //! Performs the symmetrical transformation of a torus
189 //! with respect to the point theP which is the center of the
191 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Pnt& theP) const;
193 Standard_EXPORT void Mirror (const gp_Ax1& theA1);
195 //! Performs the symmetrical transformation of a torus with
196 //! respect to an axis placement which is the axis of the
198 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax1& theA1) const;
200 Standard_EXPORT void Mirror (const gp_Ax2& theA2);
202 //! Performs the symmetrical transformation of a torus with respect
203 //! to a plane. The axis placement theA2 locates the plane of the
204 //! of the symmetry : (Location, XDirection, YDirection).
205 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax2& theA2) const;
207 void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); }
209 //! Rotates a torus. theA1 is the axis of the rotation.
210 //! theAng is the angular value of the rotation in radians.
211 Standard_NODISCARD gp_Torus Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const
214 aC.pos.Rotate (theA1, theAng);
218 void Scale (const gp_Pnt& theP, const Standard_Real theS);
220 //! Scales a torus. S is the scaling value.
221 //! The absolute value of S is used to scale the torus
222 Standard_NODISCARD gp_Torus Scaled (const gp_Pnt& theP, const Standard_Real theS) const;
224 void Transform (const gp_Trsf& theT);
226 //! Transforms a torus with the transformation theT from class Trsf.
227 Standard_NODISCARD gp_Torus Transformed (const gp_Trsf& theT) const;
229 void Translate (const gp_Vec& theV) { pos.Translate (theV); }
231 //! Translates a torus in the direction of the vector theV.
232 //! The magnitude of the translation is the vector's magnitude.
233 Standard_NODISCARD gp_Torus Translated (const gp_Vec& theV) const
236 aC.pos.Translate (theV);
240 void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); }
242 //! Translates a torus from the point theP1 to the point theP2.
243 Standard_NODISCARD gp_Torus Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
246 aC.pos.Translate (theP1, theP2);
253 Standard_Real majorRadius;
254 Standard_Real minorRadius;
258 //=======================================================================
261 //=======================================================================
262 inline void gp_Torus::Scale (const gp_Pnt& theP,
263 const Standard_Real theS)
265 pos.Scale (theP, theS);
266 Standard_Real s = theS;
275 //=======================================================================
278 //=======================================================================
279 inline gp_Torus gp_Torus::Scaled (const gp_Pnt& theP,
280 const Standard_Real theS) const
283 aC.pos.Scale (theP, theS);
284 aC.majorRadius *= theS;
285 if (aC.majorRadius < 0)
287 aC.majorRadius = -aC.majorRadius;
289 aC.minorRadius *= theS;
290 if (aC.minorRadius < 0)
292 aC.minorRadius = -aC.minorRadius;
297 //=======================================================================
298 //function : Transform
300 //=======================================================================
301 inline void gp_Torus::Transform (const gp_Trsf& theT)
303 pos.Transform (theT);
304 Standard_Real aT = theT.ScaleFactor();
313 //=======================================================================
314 //function : Transformed
316 //=======================================================================
317 inline gp_Torus gp_Torus::Transformed (const gp_Trsf& theT) const
320 aC.pos.Transform (theT);
321 aC.majorRadius *= theT.ScaleFactor();
322 if (aC.majorRadius < 0)
324 aC.majorRadius = -aC.majorRadius;
326 aC.minorRadius *= theT.ScaleFactor();
327 if (aC.minorRadius < 0)
329 aC.minorRadius = -aC.minorRadius;
334 #endif // _gp_Torus_HeaderFile