0024023: Revamp the OCCT Handle -- general
[occt.git] / src / Geom / Geom_SphericalSurface.cxx
1 // Created on: 1993-03-10
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Geom_SphericalSurface.ixx>
18
19 #include <gp_Circ.hxx>
20 #include <gp_XYZ.hxx>
21 #include <ElSLib.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_TrimmedCurve.hxx>
24 #include <Standard_ConstructionError.hxx>
25 #include <Standard_RangeError.hxx>
26
27 typedef Geom_Circle                   Circle;
28 typedef Geom_SphericalSurface         SphericalSurface;
29 typedef gp_Ax2  Ax2;
30 typedef gp_Ax3  Ax3;
31 typedef gp_Circ Circ;
32 typedef gp_Dir  Dir;
33 typedef gp_Pnt  Pnt;
34 typedef gp_Trsf Trsf;
35 typedef gp_XYZ  XYZ;
36 typedef gp_Vec  Vec;
37
38 //=======================================================================
39 //function : Copy
40 //purpose  : 
41 //=======================================================================
42
43 Handle(Geom_Geometry) Geom_SphericalSurface::Copy () const {
44  
45   Handle(Geom_SphericalSurface) Cs;
46   Cs = new SphericalSurface (pos, radius);
47   return Cs;
48 }
49
50
51
52 //=======================================================================
53 //function : Geom_SphericalSurface
54 //purpose  : 
55 //=======================================================================
56
57 Geom_SphericalSurface::Geom_SphericalSurface (const Ax3& A, const Standard_Real R) 
58 : radius (R) {
59
60   if (R < 0.0) Standard_ConstructionError::Raise();
61   pos = A;
62 }
63
64
65 //=======================================================================
66 //function : Geom_SphericalSurface
67 //purpose  : 
68 //=======================================================================
69
70 Geom_SphericalSurface::Geom_SphericalSurface (const gp_Sphere& S) 
71  :radius (S.Radius()) {
72
73   pos = S.Position();
74 }
75
76
77
78 //=======================================================================
79 //function : UReversedParameter
80 //purpose  : 
81 //=======================================================================
82
83 Standard_Real Geom_SphericalSurface::UReversedParameter( const Standard_Real U) const
84 {
85   return (2.*M_PI - U);
86 }
87
88 //=======================================================================
89 //function : VReversedParameter
90 //purpose  : 
91 //=======================================================================
92
93 Standard_Real Geom_SphericalSurface::VReversedParameter( const Standard_Real V) const
94 {
95   return (-V);
96 }
97
98
99 //=======================================================================
100 //function : Area
101 //purpose  : 
102 //=======================================================================
103
104 Standard_Real Geom_SphericalSurface::Area () const 
105 {return 4.0 * M_PI * radius * radius;}
106
107 //=======================================================================
108 //function : Radius
109 //purpose  : 
110 //=======================================================================
111
112 Standard_Real Geom_SphericalSurface::Radius () const                  
113 { return radius; }
114
115 //=======================================================================
116 //function : IsUClosed
117 //purpose  : 
118 //=======================================================================
119
120 Standard_Boolean Geom_SphericalSurface::IsUClosed () const           
121 { return Standard_True; }
122
123 //=======================================================================
124 //function : IsVClosed
125 //purpose  : 
126 //=======================================================================
127
128 Standard_Boolean Geom_SphericalSurface::IsVClosed () const            
129 { return Standard_False; }
130
131 //=======================================================================
132 //function : IsUPeriodic
133 //purpose  : 
134 //=======================================================================
135
136 Standard_Boolean Geom_SphericalSurface::IsUPeriodic () const          
137 { return Standard_True; }
138
139 //=======================================================================
140 //function : IsVPeriodic
141 //purpose  : 
142 //=======================================================================
143
144 Standard_Boolean Geom_SphericalSurface::IsVPeriodic () const          
145 { return Standard_False; }
146
147 //=======================================================================
148 //function : SetRadius
149 //purpose  : 
150 //=======================================================================
151
152 void Geom_SphericalSurface::SetRadius (const Standard_Real R) {
153
154   if (R < 0.0) { Standard_ConstructionError::Raise(); }
155   radius = R;
156 }
157
158
159 //=======================================================================
160 //function : SetSphere
161 //purpose  : 
162 //=======================================================================
163
164 void Geom_SphericalSurface::SetSphere (const gp_Sphere& S) {
165
166   radius = S.Radius();
167   pos = S.Position();
168 }
169
170
171 //=======================================================================
172 //function : Bounds
173 //purpose  : 
174 //=======================================================================
175
176 void Geom_SphericalSurface::Bounds (Standard_Real& U1, Standard_Real& U2,
177                                     Standard_Real& V1, Standard_Real& V2) const {
178
179   U1 =       0.0;  
180   U2 =  M_PI * 2.0; 
181   V1 = -M_PI / 2.0;
182   V2 =  M_PI / 2.0;
183 }
184
185
186 //=======================================================================
187 //function : Coefficients
188 //purpose  : 
189 //=======================================================================
190
191 void Geom_SphericalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
192                                           Standard_Real& B1, Standard_Real& B2, Standard_Real& B3, 
193                                           Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, 
194                                           Standard_Real& D ) const {
195
196    // Dans le repere local de la sphere :
197    // X*X + Y*Y + Z*Z - radius * radius = 0
198
199       Trsf T;
200       T.SetTransformation (pos);
201       Standard_Real T11 = T.Value (1, 1);
202       Standard_Real T12 = T.Value (1, 2);
203       Standard_Real T13 = T.Value (1, 3);
204       Standard_Real T14 = T.Value (1, 4);
205       Standard_Real T21 = T.Value (2, 1);
206       Standard_Real T22 = T.Value (2, 2);
207       Standard_Real T23 = T.Value (2, 3);
208       Standard_Real T24 = T.Value (2, 4);
209       Standard_Real T31 = T.Value (3, 1);
210       Standard_Real T32 = T.Value (3, 2);
211       Standard_Real T33 = T.Value (3, 3);
212       Standard_Real T34 = T.Value (3, 4);
213       A1 = T11 * T11 + T21 * T21 + T31 * T31;
214       A2 = T12 * T12 + T22 * T22 + T32 * T32;
215       A3 = T13 * T13 + T23 * T23 + T33 * T33;
216       B1 = T11 * T12 + T21 * T22 + T31 * T32;
217       B2 = T11 * T13 + T21 * T23 + T31 * T33;
218       B3 = T12 * T13 + T22 * T23 + T32 * T33;
219       C1 = T11 * T14 + T21 * T24 + T31 * T34;
220       C2 = T12 * T14 + T22 * T24 + T32 * T34;
221       C3 = T13 * T14 + T23 * T24 + T33 * T34;
222       D = T14 * T14 + T24 * T24 + T34 * T34 - radius * radius;
223 }
224
225
226 //=======================================================================
227 //function : D0
228 //purpose  : 
229 //=======================================================================
230
231 void Geom_SphericalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const 
232 {
233   ElSLib::SphereD0(U,V,pos,radius,P);
234 }
235
236
237 //=======================================================================
238 //function : D1
239 //purpose  : 
240 //=======================================================================
241
242 void Geom_SphericalSurface::D1 (const Standard_Real U, const Standard_Real V  , 
243                                       Pnt& P,       Vec& D1U, Vec& D1V
244                                ) const 
245 {
246   ElSLib::SphereD1 (U, V, pos, radius, P ,D1U, D1V);
247 }
248
249
250 //=======================================================================
251 //function : D2
252 //purpose  : 
253 //=======================================================================
254
255 void Geom_SphericalSurface::D2 (const Standard_Real U, const Standard_Real V,
256                                 Pnt& P,
257                                 Vec& D1U, Vec& D1V, 
258                                 Vec& D2U, Vec& D2V, Vec& D2UV ) const
259 {
260   ElSLib::SphereD2 (U, V, pos, radius, P, D1U, D1V, D2U, D2V, D2UV);
261 }
262
263
264 //=======================================================================
265 //function : D3
266 //purpose  : 
267 //=======================================================================
268
269 void Geom_SphericalSurface::D3 (const Standard_Real U, const Standard_Real V, 
270                                 Pnt& P,
271                                 Vec& D1U, Vec& D1V, 
272                                 Vec& D2U, Vec& D2V, Vec& D2UV,
273                                 Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV
274                                ) const
275 {
276   ElSLib::SphereD3 (U, V, pos, radius, P, D1U, D1V, D2U, D2V,
277                     D2UV, D3U, D3V, D3UUV, D3UVV);
278 }
279
280
281 //=======================================================================
282 //function : DN
283 //purpose  : 
284 //=======================================================================
285
286 Vec Geom_SphericalSurface::DN (const Standard_Real U, const Standard_Real V, 
287                                const Standard_Integer Nu, const Standard_Integer Nv) const {
288
289    Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, " ");
290    return  ElSLib::SphereDN (U, V, pos, radius, Nu, Nv);
291 }
292
293
294 //=======================================================================
295 //function : Sphere
296 //purpose  : 
297 //=======================================================================
298
299 gp_Sphere Geom_SphericalSurface::Sphere () const {
300
301   return gp_Sphere (pos, radius);
302 }
303
304
305 //=======================================================================
306 //function : UIso
307 //purpose  : 
308 //=======================================================================
309
310 Handle(Geom_Curve) Geom_SphericalSurface::UIso (const Standard_Real U) const 
311 {
312   Handle(Geom_Circle) GC = new Geom_Circle(ElSLib::SphereUIso(pos,radius,U));
313   Handle(Geom_TrimmedCurve) iso = new Geom_TrimmedCurve(GC,-M_PI/2.,M_PI/2);
314   return iso;
315 }
316
317
318 //=======================================================================
319 //function : VIso
320 //purpose  : 
321 //=======================================================================
322
323 Handle(Geom_Curve) Geom_SphericalSurface::VIso (const Standard_Real V) const 
324 {
325   Handle(Geom_Circle) 
326     GC = new Geom_Circle(ElSLib::SphereVIso(pos,radius,V));
327   return GC;
328 }
329
330
331 //=======================================================================
332 //function : Volume
333 //purpose  : 
334 //=======================================================================
335
336 Standard_Real Geom_SphericalSurface::Volume () const {
337
338    return (4.0 * M_PI * radius * radius * radius)/3.0;
339 }
340
341
342
343 //=======================================================================
344 //function : Transform
345 //purpose  : 
346 //=======================================================================
347
348 void Geom_SphericalSurface::Transform (const Trsf& T) {
349
350    radius = radius * Abs(T.ScaleFactor());
351    pos.Transform (T);
352 }