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_Sphere_HeaderFile |
16 | #define _gp_Sphere_HeaderFile |
17 | |
42cf5bc1 |
18 | #include <gp_Ax1.hxx> |
d5477f8c |
19 | #include <gp_Ax3.hxx> |
20 | #include <Standard_ConstructionError.hxx> |
42cf5bc1 |
21 | |
22 | //! Describes a sphere. |
23 | //! A sphere is defined by its radius and positioned in space |
24 | //! with a coordinate system (a gp_Ax3 object). The origin of |
25 | //! the coordinate system is the center of the sphere. This |
26 | //! coordinate system is the "local coordinate system" of the sphere. |
27 | //! Note: when a gp_Sphere sphere is converted into a |
28 | //! Geom_SphericalSurface sphere, some implicit |
29 | //! properties of its local coordinate system are used explicitly: |
30 | //! - its origin, "X Direction", "Y Direction" and "main |
31 | //! Direction" are used directly to define the parametric |
32 | //! directions on the sphere and the origin of the parameters, |
33 | //! - its implicit orientation (right-handed or left-handed) |
34 | //! gives the orientation (direct, indirect) to the |
35 | //! Geom_SphericalSurface sphere. |
36 | //! See Also |
37 | //! gce_MakeSphere which provides functions for more |
38 | //! complex sphere constructions |
39 | //! Geom_SphericalSurface which provides additional |
40 | //! functions for constructing spheres and works, in |
41 | //! particular, with the parametric equations of spheres. |
42 | class gp_Sphere |
43 | { |
44 | public: |
45 | |
46 | DEFINE_STANDARD_ALLOC |
47 | |
42cf5bc1 |
48 | //! Creates an indefinite sphere. |
d5477f8c |
49 | gp_Sphere() |
50 | : radius (RealLast()) |
51 | {} |
42cf5bc1 |
52 | |
d5477f8c |
53 | //! Constructs a sphere with radius theRadius, centered on the origin |
54 | //! of theA3. theA3 is the local coordinate system of the sphere. |
42cf5bc1 |
55 | //! Warnings : |
56 | //! It is not forbidden to create a sphere with null radius. |
d5477f8c |
57 | //! Raises ConstructionError if theRadius < 0.0 |
58 | gp_Sphere (const gp_Ax3& theA3, const Standard_Real theRadius) |
59 | : pos (theA3), |
60 | radius (theRadius) |
61 | { |
62 | Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Sphere() - radius should be >= 0"); |
63 | } |
64 | |
42cf5bc1 |
65 | //! Changes the center of the sphere. |
d5477f8c |
66 | void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); } |
67 | |
42cf5bc1 |
68 | //! Changes the local coordinate system of the sphere. |
d5477f8c |
69 | void SetPosition (const gp_Ax3& theA3) { pos = theA3; } |
70 | |
71 | //! Assigns theR the radius of the Sphere. |
42cf5bc1 |
72 | //! Warnings : |
73 | //! It is not forbidden to create a sphere with null radius. |
d5477f8c |
74 | //! Raises ConstructionError if theR < 0.0 |
75 | void SetRadius (const Standard_Real theR) |
76 | { |
77 | Standard_ConstructionError_Raise_if (theR < 0.0, "gp_Sphere::SetRadius() - radius should be >= 0"); |
78 | radius = theR; |
79 | } |
42cf5bc1 |
80 | |
08eda8e3 |
81 | //! Computes the area of the sphere. |
d5477f8c |
82 | Standard_Real Area() const |
83 | { |
84 | return 4.0 * M_PI * radius * radius; |
85 | } |
42cf5bc1 |
86 | |
87 | //! Computes the coefficients of the implicit equation of the quadric |
88 | //! in the absolute cartesian coordinates system : |
08eda8e3 |
89 | //! @code |
d5477f8c |
90 | //! theA1.X**2 + theA2.Y**2 + theA3.Z**2 + 2.(theB1.X.Y + theB2.X.Z + theB3.Y.Z) + |
91 | //! 2.(theC1.X + theC2.Y + theC3.Z) + theD = 0.0 |
08eda8e3 |
92 | //! @endcode |
d5477f8c |
93 | Standard_EXPORT void Coefficients (Standard_Real& theA1, Standard_Real& theA2, Standard_Real& theA3, |
94 | Standard_Real& theB1, Standard_Real& theB2, Standard_Real& theB3, |
95 | Standard_Real& theC1, Standard_Real& theC2, Standard_Real& theC3, Standard_Real& theD) const; |
96 | |
42cf5bc1 |
97 | //! Reverses the U parametrization of the sphere |
98 | //! reversing the YAxis. |
d5477f8c |
99 | void UReverse() { pos.YReverse(); } |
100 | |
42cf5bc1 |
101 | //! Reverses the V parametrization of the sphere |
102 | //! reversing the ZAxis. |
d5477f8c |
103 | void VReverse() { pos.ZReverse(); } |
104 | |
42cf5bc1 |
105 | //! Returns true if the local coordinate system of this sphere |
106 | //! is right-handed. |
d5477f8c |
107 | Standard_Boolean Direct() const { return pos.Direct(); } |
108 | |
42cf5bc1 |
109 | //! --- Purpose ; |
110 | //! Returns the center of the sphere. |
d5477f8c |
111 | const gp_Pnt& Location() const { return pos.Location(); } |
42cf5bc1 |
112 | |
113 | //! Returns the local coordinates system of the sphere. |
d5477f8c |
114 | const gp_Ax3& Position() const { return pos; } |
115 | |
42cf5bc1 |
116 | //! Returns the radius of the sphere. |
d5477f8c |
117 | Standard_Real Radius() const { return radius; } |
118 | |
42cf5bc1 |
119 | //! Computes the volume of the sphere |
d5477f8c |
120 | Standard_Real Volume() const |
121 | { |
122 | return (4.0 * M_PI * radius * radius * radius) / 3.0; |
123 | } |
124 | |
42cf5bc1 |
125 | //! Returns the axis X of the sphere. |
d5477f8c |
126 | gp_Ax1 XAxis() const |
127 | { |
128 | return gp_Ax1 (pos.Location(), pos.XDirection()); |
129 | } |
130 | |
42cf5bc1 |
131 | //! Returns the axis Y of the sphere. |
d5477f8c |
132 | gp_Ax1 YAxis() const |
133 | { |
134 | return gp_Ax1 (pos.Location(), pos.YDirection()); |
135 | } |
136 | |
137 | Standard_EXPORT void Mirror (const gp_Pnt& theP); |
42cf5bc1 |
138 | |
139 | //! Performs the symmetrical transformation of a sphere |
d5477f8c |
140 | //! with respect to the point theP which is the center of the |
42cf5bc1 |
141 | //! symmetry. |
d5477f8c |
142 | Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Pnt& theP) const; |
143 | |
144 | Standard_EXPORT void Mirror (const gp_Ax1& theA1); |
42cf5bc1 |
145 | |
146 | //! Performs the symmetrical transformation of a sphere with |
147 | //! respect to an axis placement which is the axis of the |
148 | //! symmetry. |
d5477f8c |
149 | Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Ax1& theA1) const; |
150 | |
151 | Standard_EXPORT void Mirror (const gp_Ax2& theA2); |
42cf5bc1 |
152 | |
153 | //! Performs the symmetrical transformation of a sphere with respect |
d5477f8c |
154 | //! to a plane. The axis placement theA2 locates the plane of the |
42cf5bc1 |
155 | //! of the symmetry : (Location, XDirection, YDirection). |
d5477f8c |
156 | Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Ax2& theA2) const; |
42cf5bc1 |
157 | |
d5477f8c |
158 | void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } |
42cf5bc1 |
159 | |
d5477f8c |
160 | //! Rotates a sphere. theA1 is the axis of the rotation. |
161 | //! theAng is the angular value of the rotation in radians. |
162 | Standard_NODISCARD gp_Sphere Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const |
163 | { |
164 | gp_Sphere aC = *this; |
165 | aC.pos.Rotate (theA1, theAng); |
166 | return aC; |
167 | } |
42cf5bc1 |
168 | |
d5477f8c |
169 | void Scale (const gp_Pnt& theP, const Standard_Real theS); |
42cf5bc1 |
170 | |
d5477f8c |
171 | //! Scales a sphere. theS is the scaling value. |
172 | //! The absolute value of S is used to scale the sphere |
173 | Standard_NODISCARD gp_Sphere Scaled (const gp_Pnt& theP, const Standard_Real theS) const; |
42cf5bc1 |
174 | |
d5477f8c |
175 | void Transform (const gp_Trsf& theT); |
42cf5bc1 |
176 | |
d5477f8c |
177 | //! Transforms a sphere with the transformation theT from class Trsf. |
178 | Standard_NODISCARD gp_Sphere Transformed (const gp_Trsf& theT) const; |
42cf5bc1 |
179 | |
d5477f8c |
180 | void Translate (const gp_Vec& theV) { pos.Translate (theV); } |
42cf5bc1 |
181 | |
d5477f8c |
182 | //! Translates a sphere in the direction of the vector theV. |
183 | //! The magnitude of the translation is the vector's magnitude. |
184 | Standard_NODISCARD gp_Sphere Translated (const gp_Vec& theV) const |
185 | { |
186 | gp_Sphere aC = *this; |
187 | aC.pos.Translate (theV); |
188 | return aC; |
189 | } |
190 | |
191 | void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } |
192 | |
193 | //! Translates a sphere from the point theP1 to the point theP2. |
194 | Standard_NODISCARD gp_Sphere Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const |
195 | { |
196 | gp_Sphere aC = *this; |
197 | aC.pos.Translate (theP1, theP2); |
198 | return aC; |
199 | } |
42cf5bc1 |
200 | |
201 | private: |
202 | |
42cf5bc1 |
203 | gp_Ax3 pos; |
204 | Standard_Real radius; |
205 | |
42cf5bc1 |
206 | }; |
207 | |
d5477f8c |
208 | //======================================================================= |
209 | //function : Scale |
210 | // purpose : |
211 | //======================================================================= |
212 | inline void gp_Sphere::Scale (const gp_Pnt& theP, const Standard_Real theS) |
213 | { |
214 | pos.Scale (theP, theS); |
215 | radius *= theS; |
216 | if (radius < 0) |
217 | { |
218 | radius = -radius; |
219 | } |
220 | } |
221 | |
222 | //======================================================================= |
223 | //function : Scaled |
224 | // purpose : |
225 | //======================================================================= |
226 | inline gp_Sphere gp_Sphere::Scaled (const gp_Pnt& theP, const Standard_Real theS) const |
227 | { |
228 | gp_Sphere aC = *this; |
229 | aC.pos.Scale (theP, theS); |
230 | aC.radius *= theS; |
231 | if (aC.radius < 0) |
232 | { |
233 | aC.radius = -aC.radius; |
234 | } |
235 | return aC; |
236 | } |
237 | |
238 | //======================================================================= |
239 | //function : Transform |
240 | // purpose : |
241 | //======================================================================= |
242 | inline void gp_Sphere::Transform (const gp_Trsf& theT) |
243 | { |
244 | pos.Transform(theT); |
245 | radius *= theT.ScaleFactor(); |
246 | if (radius < 0) |
247 | { |
248 | radius = -radius; |
249 | } |
250 | } |
251 | |
252 | //======================================================================= |
253 | //function : Transformed |
254 | // purpose : |
255 | //======================================================================= |
256 | inline gp_Sphere gp_Sphere::Transformed (const gp_Trsf& theT) const |
257 | { |
258 | gp_Sphere aC = *this; |
259 | aC.pos.Transform (theT); |
260 | aC.radius *= theT.ScaleFactor(); |
261 | if (aC.radius < 0) |
262 | { |
263 | aC.radius = -aC.radius; |
264 | } |
265 | return aC; |
266 | } |
42cf5bc1 |
267 | |
268 | #endif // _gp_Sphere_HeaderFile |