0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / gp / gp_Torus.hxx
CommitLineData
42cf5bc1 1// Copyright (c) 1991-1999 Matra Datavision
2// Copyright (c) 1999-2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
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.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#ifndef _gp_Torus_HeaderFile
16#define _gp_Torus_HeaderFile
17
d5477f8c 18#include <gp_Ax1.hxx>
42cf5bc1 19#include <gp_Ax3.hxx>
d5477f8c 20#include <Standard_ConstructionError.hxx>
42cf5bc1 21#include <TColStd_Array1OfReal.hxx>
42cf5bc1 22
23//! Describes a torus.
24//! A torus is defined by its major and minor radii and
25//! positioned in space with a coordinate system (a gp_Ax3
26//! object) as follows:
27//! - The origin of the coordinate system is the center of the torus;
28//! - The surface is obtained by rotating a circle of radius
29//! equal to the minor radius of the torus about the "main
30//! Direction" of the coordinate system. This circle is
31//! located in the plane defined by the origin, the "X
32//! Direction" and the "main Direction" of the coordinate
33//! system. It is centered on the "X Axis" of this coordinate
34//! system, and located at a distance, from the origin of
35//! this coordinate system, equal to the major radius of the torus;
36//! - The "X Direction" and "Y Direction" define the
37//! reference plane of the torus.
38//! The coordinate system described above is the "local
39//! coordinate system" of the torus.
40//! Note: when a gp_Torus torus is converted into a
41//! Geom_ToroidalSurface torus, some implicit properties
42//! of its local coordinate system are used explicitly:
43//! - its origin, "X Direction", "Y Direction" and "main
44//! Direction" are used directly to define the parametric
45//! directions on the torus and the origin of the parameters,
46//! - its implicit orientation (right-handed or left-handed)
47//! gives the orientation (direct, indirect) to the
48//! Geom_ToroidalSurface torus.
49//! See Also
50//! gce_MakeTorus which provides functions for more
51//! complex torus constructions
52//! Geom_ToroidalSurface which provides additional
53//! functions for constructing tori and works, in particular,
54//! with the parametric equations of tori.
55class gp_Torus
56{
57public:
58
59 DEFINE_STANDARD_ALLOC
60
42cf5bc1 61 //! creates an indefinite Torus.
d5477f8c 62 gp_Torus()
63 : majorRadius (RealLast()),
64 minorRadius (RealSmall())
65 {}
42cf5bc1 66
67 //! a torus centered on the origin of coordinate system
d5477f8c 68 //! theA3, with major radius theMajorRadius and minor radius
69 //! theMinorRadius, and with the reference plane defined
70 //! by the origin, the "X Direction" and the "Y Direction" of theA3.
42cf5bc1 71 //! Warnings :
72 //! It is not forbidden to create a torus with
d5477f8c 73 //! theMajorRadius = theMinorRadius = 0.0
74 //! Raises ConstructionError if theMinorRadius < 0.0 or if theMajorRadius < 0.0
75 gp_Torus (const gp_Ax3& theA3, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius)
76 : pos (theA3),
77 majorRadius (theMajorRadius),
78 minorRadius (theMinorRadius)
79 {
80 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0,
81 "gp_Torus() - invalid construction parameters");
82 }
83
42cf5bc1 84 //! Modifies this torus, by redefining its local coordinate
85 //! system so that:
86 //! - its origin and "main Direction" become those of the
d5477f8c 87 //! axis theA1 (the "X Direction" and "Y Direction" are then recomputed).
88 //! Raises ConstructionError if the direction of theA1 is parallel to the "XDirection"
42cf5bc1 89 //! of the coordinate system of the toroidal surface.
d5477f8c 90 void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); }
91
42cf5bc1 92 //! Changes the location of the torus.
d5477f8c 93 void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); }
94
42cf5bc1 95 //! Assigns value to the major radius of this torus.
d5477f8c 96 //! Raises ConstructionError if theMajorRadius - MinorRadius <= Resolution()
97 void SetMajorRadius (const Standard_Real theMajorRadius)
98 {
99 Standard_ConstructionError_Raise_if (theMajorRadius - minorRadius <= gp::Resolution(),
100 "gp_Torus::SetMajorRadius() - invalid input parameters");
101 majorRadius = theMajorRadius;
102 }
103
42cf5bc1 104 //! Assigns value to the minor radius of this torus.
d5477f8c 105 //! Raises ConstructionError if theMinorRadius < 0.0 or if
106 //! MajorRadius - theMinorRadius <= Resolution from gp.
107 void SetMinorRadius (const Standard_Real theMinorRadius)
108 {
109 Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || majorRadius - theMinorRadius <= gp::Resolution(),
110 "gp_Torus::SetMinorRadius() - invalid input parameters");
111 minorRadius = theMinorRadius;
112 }
113
42cf5bc1 114 //! Changes the local coordinate system of the surface.
d5477f8c 115 void SetPosition (const gp_Ax3& theA3) { pos = theA3; }
116
42cf5bc1 117 //! Computes the area of the torus.
d5477f8c 118 Standard_Real Area() const { return 4.0 * M_PI * M_PI * minorRadius * majorRadius; }
119
42cf5bc1 120 //! Reverses the U parametrization of the torus
121 //! reversing the YAxis.
d5477f8c 122 void UReverse() { pos.YReverse(); }
123
42cf5bc1 124 //! Reverses the V parametrization of the torus
125 //! reversing the ZAxis.
d5477f8c 126 void VReverse() { pos.ZReverse(); }
127
42cf5bc1 128 //! returns true if the Ax3, the local coordinate system of this torus, is right handed.
d5477f8c 129 Standard_Boolean Direct() const { return pos.Direct(); }
130
42cf5bc1 131 //! returns the symmetry axis of the torus.
d5477f8c 132 const gp_Ax1& Axis() const { return pos.Axis(); }
133
42cf5bc1 134 //! Computes the coefficients of the implicit equation of the surface
0b4abfb9 135 //! in the absolute Cartesian coordinate system:
08eda8e3 136 //! @code
0b4abfb9 137 //! Coef(1) * X^4 + Coef(2) * Y^4 + Coef(3) * Z^4 +
138 //! Coef(4) * X^3 * Y + Coef(5) * X^3 * Z + Coef(6) * Y^3 * X +
139 //! Coef(7) * Y^3 * Z + Coef(8) * Z^3 * X + Coef(9) * Z^3 * Y +
140 //! Coef(10) * X^2 * Y^2 + Coef(11) * X^2 * Z^2 +
141 //! Coef(12) * Y^2 * Z^2 + Coef(13) * X^2 * Y * Z +
142 //! Coef(14) * X * Y^2 * Z + Coef(15) * X * Y * Z^2 +
143 //! Coef(16) * X^3 + Coef(17) * Y^3 + Coef(18) * Z^3 +
144 //! Coef(19) * X^2 * Y + Coef(20) * X^2 * Z + Coef(21) * Y^2 * X +
145 //! Coef(22) * Y^2 * Z + Coef(23) * Z^2 * X + Coef(24) * Z^2 * Y +
146 //! Coef(25) * X * Y * Z +
147 //! Coef(26) * X^2 + Coef(27) * Y^2 + Coef(28) * Z^2 +
148 //! Coef(29) * X * Y + Coef(30) * X * Z + Coef(31) * Y * Z +
149 //! Coef(32) * X + Coef(33) * Y + Coef(34) * Z +
150 //! Coef(35) = 0.0
08eda8e3 151 //! @endcode
d5477f8c 152 //! Raises DimensionError if the length of theCoef is lower than 35.
153 Standard_EXPORT void Coefficients (TColStd_Array1OfReal& theCoef) const;
154
42cf5bc1 155 //! Returns the Torus's location.
d5477f8c 156 const gp_Pnt& Location() const { return pos.Location(); }
157
42cf5bc1 158 //! Returns the local coordinates system of the torus.
d5477f8c 159 const gp_Ax3& Position() const { return pos; }
160
42cf5bc1 161 //! returns the major radius of the torus.
d5477f8c 162 Standard_Real MajorRadius() const { return majorRadius; }
163
42cf5bc1 164 //! returns the minor radius of the torus.
d5477f8c 165 Standard_Real MinorRadius() const { return minorRadius; }
166
42cf5bc1 167 //! Computes the volume of the torus.
d5477f8c 168 Standard_Real Volume() const
169 {
170 return (M_PI * minorRadius * minorRadius) * (2.0 * M_PI * majorRadius);
171 }
172
42cf5bc1 173 //! returns the axis X of the torus.
d5477f8c 174 gp_Ax1 XAxis() const
175 {
176 return gp_Ax1 (pos.Location(), pos.XDirection());
177 }
178
42cf5bc1 179 //! returns the axis Y of the torus.
d5477f8c 180 gp_Ax1 YAxis() const
181 {
182 return gp_Ax1 (pos.Location(), pos.YDirection());
183 }
184
185 Standard_EXPORT void Mirror (const gp_Pnt& theP);
42cf5bc1 186
187 //! Performs the symmetrical transformation of a torus
d5477f8c 188 //! with respect to the point theP which is the center of the
42cf5bc1 189 //! symmetry.
d5477f8c 190 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Pnt& theP) const;
191
192 Standard_EXPORT void Mirror (const gp_Ax1& theA1);
42cf5bc1 193
194 //! Performs the symmetrical transformation of a torus with
195 //! respect to an axis placement which is the axis of the
196 //! symmetry.
d5477f8c 197 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax1& theA1) const;
198
199 Standard_EXPORT void Mirror (const gp_Ax2& theA2);
42cf5bc1 200
201 //! Performs the symmetrical transformation of a torus with respect
d5477f8c 202 //! to a plane. The axis placement theA2 locates the plane of the
42cf5bc1 203 //! of the symmetry : (Location, XDirection, YDirection).
d5477f8c 204 Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax2& theA2) const;
42cf5bc1 205
d5477f8c 206 void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); }
42cf5bc1 207
d5477f8c 208 //! Rotates a torus. theA1 is the axis of the rotation.
209 //! theAng is the angular value of the rotation in radians.
210 Standard_NODISCARD gp_Torus Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const
211 {
212 gp_Torus aC = *this;
213 aC.pos.Rotate (theA1, theAng);
214 return aC;
215 }
42cf5bc1 216
d5477f8c 217 void Scale (const gp_Pnt& theP, const Standard_Real theS);
42cf5bc1 218
d5477f8c 219 //! Scales a torus. S is the scaling value.
220 //! The absolute value of S is used to scale the torus
221 Standard_NODISCARD gp_Torus Scaled (const gp_Pnt& theP, const Standard_Real theS) const;
42cf5bc1 222
d5477f8c 223 void Transform (const gp_Trsf& theT);
42cf5bc1 224
d5477f8c 225 //! Transforms a torus with the transformation theT from class Trsf.
226 Standard_NODISCARD gp_Torus Transformed (const gp_Trsf& theT) const;
42cf5bc1 227
d5477f8c 228 void Translate (const gp_Vec& theV) { pos.Translate (theV); }
42cf5bc1 229
d5477f8c 230 //! Translates a torus in the direction of the vector theV.
231 //! The magnitude of the translation is the vector's magnitude.
232 Standard_NODISCARD gp_Torus Translated (const gp_Vec& theV) const
233 {
234 gp_Torus aC = *this;
235 aC.pos.Translate (theV);
236 return aC;
237 }
238
239 void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); }
240
241 //! Translates a torus from the point theP1 to the point theP2.
242 Standard_NODISCARD gp_Torus Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
243 {
244 gp_Torus aC = *this;
245 aC.pos.Translate (theP1, theP2);
246 return aC;
247 }
42cf5bc1 248
249private:
250
42cf5bc1 251 gp_Ax3 pos;
252 Standard_Real majorRadius;
253 Standard_Real minorRadius;
254
42cf5bc1 255};
256
d5477f8c 257//=======================================================================
258//function : Scale
259// purpose :
260//=======================================================================
261inline void gp_Torus::Scale (const gp_Pnt& theP,
262 const Standard_Real theS)
263{
264 pos.Scale (theP, theS);
265 Standard_Real s = theS;
266 if (s < 0)
267 {
268 s = -s;
269 }
270 majorRadius *= s;
271 minorRadius *= s;
272}
273
274//=======================================================================
275//function : Scaled
276// purpose :
277//=======================================================================
278inline gp_Torus gp_Torus::Scaled (const gp_Pnt& theP,
279 const Standard_Real theS) const
280{
281 gp_Torus aC = *this;
282 aC.pos.Scale (theP, theS);
283 aC.majorRadius *= theS;
284 if (aC.majorRadius < 0)
285 {
286 aC.majorRadius = -aC.majorRadius;
287 }
288 aC.minorRadius *= theS;
289 if (aC.minorRadius < 0)
290 {
291 aC.minorRadius = -aC.minorRadius;
292 }
293 return aC;
294}
295
296//=======================================================================
297//function : Transform
298// purpose :
299//=======================================================================
300inline void gp_Torus::Transform (const gp_Trsf& theT)
301{
302 pos.Transform (theT);
303 Standard_Real aT = theT.ScaleFactor();
304 if (aT < 0)
305 {
306 aT = -aT;
307 }
308 minorRadius *= aT;
309 majorRadius *= aT;
310}
311
312//=======================================================================
313//function : Transformed
314// purpose :
315//=======================================================================
316inline gp_Torus gp_Torus::Transformed (const gp_Trsf& theT) const
317{
318 gp_Torus aC = *this;
319 aC.pos.Transform (theT);
320 aC.majorRadius *= theT.ScaleFactor();
321 if (aC.majorRadius < 0)
322 {
323 aC.majorRadius = -aC.majorRadius;
324 }
325 aC.minorRadius *= theT.ScaleFactor();
326 if (aC.minorRadius < 0)
327 {
328 aC.minorRadius = -aC.minorRadius;
329 }
330 return aC;
331}
42cf5bc1 332
333#endif // _gp_Torus_HeaderFile