1 // Created on: 1993-03-10
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Geom_SphericalSurface.ixx>
19 #include <gp_Circ.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_TrimmedCurve.hxx>
24 #include <Standard_ConstructionError.hxx>
25 #include <Standard_RangeError.hxx>
27 typedef Geom_Circle Circle;
28 typedef Geom_SphericalSurface SphericalSurface;
29 typedef Handle(Geom_SphericalSurface) Handle(SphericalSurface);
30 typedef Handle(Geom_Curve) Handle(Curve);
31 typedef Handle(Geom_Circle) Handle(Circle);
44 //=======================================================================
47 //=======================================================================
49 Handle(Geom_Geometry) Geom_SphericalSurface::Copy () const {
51 Handle(SphericalSurface) Cs;
52 Cs = new SphericalSurface (pos, radius);
58 //=======================================================================
59 //function : Geom_SphericalSurface
61 //=======================================================================
63 Geom_SphericalSurface::Geom_SphericalSurface (const Ax3& A, const Standard_Real R)
66 if (R < 0.0) Standard_ConstructionError::Raise();
71 //=======================================================================
72 //function : Geom_SphericalSurface
74 //=======================================================================
76 Geom_SphericalSurface::Geom_SphericalSurface (const gp_Sphere& S)
77 :radius (S.Radius()) {
84 //=======================================================================
85 //function : UReversedParameter
87 //=======================================================================
89 Standard_Real Geom_SphericalSurface::UReversedParameter( const Standard_Real U) const
94 //=======================================================================
95 //function : VReversedParameter
97 //=======================================================================
99 Standard_Real Geom_SphericalSurface::VReversedParameter( const Standard_Real V) const
105 //=======================================================================
108 //=======================================================================
110 Standard_Real Geom_SphericalSurface::Area () const
111 {return 4.0 * M_PI * radius * radius;}
113 //=======================================================================
116 //=======================================================================
118 Standard_Real Geom_SphericalSurface::Radius () const
121 //=======================================================================
122 //function : IsUClosed
124 //=======================================================================
126 Standard_Boolean Geom_SphericalSurface::IsUClosed () const
127 { return Standard_True; }
129 //=======================================================================
130 //function : IsVClosed
132 //=======================================================================
134 Standard_Boolean Geom_SphericalSurface::IsVClosed () const
135 { return Standard_False; }
137 //=======================================================================
138 //function : IsUPeriodic
140 //=======================================================================
142 Standard_Boolean Geom_SphericalSurface::IsUPeriodic () const
143 { return Standard_True; }
145 //=======================================================================
146 //function : IsVPeriodic
148 //=======================================================================
150 Standard_Boolean Geom_SphericalSurface::IsVPeriodic () const
151 { return Standard_False; }
153 //=======================================================================
154 //function : SetRadius
156 //=======================================================================
158 void Geom_SphericalSurface::SetRadius (const Standard_Real R) {
160 if (R < 0.0) { Standard_ConstructionError::Raise(); }
165 //=======================================================================
166 //function : SetSphere
168 //=======================================================================
170 void Geom_SphericalSurface::SetSphere (const gp_Sphere& S) {
177 //=======================================================================
180 //=======================================================================
182 void Geom_SphericalSurface::Bounds (Standard_Real& U1, Standard_Real& U2,
183 Standard_Real& V1, Standard_Real& V2) const {
192 //=======================================================================
193 //function : Coefficients
195 //=======================================================================
197 void Geom_SphericalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
198 Standard_Real& B1, Standard_Real& B2, Standard_Real& B3,
199 Standard_Real& C1, Standard_Real& C2, Standard_Real& C3,
200 Standard_Real& D ) const {
202 // Dans le repere local de la sphere :
203 // X*X + Y*Y + Z*Z - radius * radius = 0
206 T.SetTransformation (pos);
207 Standard_Real T11 = T.Value (1, 1);
208 Standard_Real T12 = T.Value (1, 2);
209 Standard_Real T13 = T.Value (1, 3);
210 Standard_Real T14 = T.Value (1, 4);
211 Standard_Real T21 = T.Value (2, 1);
212 Standard_Real T22 = T.Value (2, 2);
213 Standard_Real T23 = T.Value (2, 3);
214 Standard_Real T24 = T.Value (2, 4);
215 Standard_Real T31 = T.Value (3, 1);
216 Standard_Real T32 = T.Value (3, 2);
217 Standard_Real T33 = T.Value (3, 3);
218 Standard_Real T34 = T.Value (3, 4);
219 A1 = T11 * T11 + T21 * T21 + T31 * T31;
220 A2 = T12 * T12 + T22 * T22 + T32 * T32;
221 A3 = T13 * T13 + T23 * T23 + T33 * T33;
222 B1 = T11 * T12 + T21 * T22 + T31 * T32;
223 B2 = T11 * T13 + T21 * T23 + T31 * T33;
224 B3 = T12 * T13 + T22 * T23 + T32 * T33;
225 C1 = T11 * T14 + T21 * T24 + T31 * T34;
226 C2 = T12 * T14 + T22 * T24 + T32 * T34;
227 C3 = T13 * T14 + T23 * T24 + T33 * T34;
228 D = T14 * T14 + T24 * T24 + T34 * T34 - radius * radius;
232 //=======================================================================
235 //=======================================================================
237 void Geom_SphericalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const
239 ElSLib::SphereD0(U,V,pos,radius,P);
243 //=======================================================================
246 //=======================================================================
248 void Geom_SphericalSurface::D1 (const Standard_Real U, const Standard_Real V ,
249 Pnt& P, Vec& D1U, Vec& D1V
252 ElSLib::SphereD1 (U, V, pos, radius, P ,D1U, D1V);
256 //=======================================================================
259 //=======================================================================
261 void Geom_SphericalSurface::D2 (const Standard_Real U, const Standard_Real V,
264 Vec& D2U, Vec& D2V, Vec& D2UV ) const
266 ElSLib::SphereD2 (U, V, pos, radius, P, D1U, D1V, D2U, D2V, D2UV);
270 //=======================================================================
273 //=======================================================================
275 void Geom_SphericalSurface::D3 (const Standard_Real U, const Standard_Real V,
278 Vec& D2U, Vec& D2V, Vec& D2UV,
279 Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV
282 ElSLib::SphereD3 (U, V, pos, radius, P, D1U, D1V, D2U, D2V,
283 D2UV, D3U, D3V, D3UUV, D3UVV);
287 //=======================================================================
290 //=======================================================================
292 Vec Geom_SphericalSurface::DN (const Standard_Real U, const Standard_Real V,
293 const Standard_Integer Nu, const Standard_Integer Nv) const {
295 Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, " ");
296 return ElSLib::SphereDN (U, V, pos, radius, Nu, Nv);
300 //=======================================================================
303 //=======================================================================
305 gp_Sphere Geom_SphericalSurface::Sphere () const {
307 return gp_Sphere (pos, radius);
311 //=======================================================================
314 //=======================================================================
316 Handle(Curve) Geom_SphericalSurface::UIso (const Standard_Real U) const
318 Handle(Geom_Circle) GC = new Geom_Circle(ElSLib::SphereUIso(pos,radius,U));
319 Handle(Geom_TrimmedCurve) iso = new Geom_TrimmedCurve(GC,-M_PI/2.,M_PI/2);
324 //=======================================================================
327 //=======================================================================
329 Handle(Curve) Geom_SphericalSurface::VIso (const Standard_Real V) const
332 GC = new Geom_Circle(ElSLib::SphereVIso(pos,radius,V));
337 //=======================================================================
340 //=======================================================================
342 Standard_Real Geom_SphericalSurface::Volume () const {
344 return (4.0 * M_PI * radius * radius * radius)/3.0;
349 //=======================================================================
350 //function : Transform
352 //=======================================================================
354 void Geom_SphericalSurface::Transform (const Trsf& T) {
356 radius = radius * Abs(T.ScaleFactor());