ffd8307da72878eb9fea166d4e170ab332705a3d
[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 Handle(Geom_SphericalSurface) Handle(SphericalSurface);
30 typedef Handle(Geom_Curve)            Handle(Curve);
31 typedef Handle(Geom_Circle)           Handle(Circle);
32 typedef gp_Ax2  Ax2;
33 typedef gp_Ax3  Ax3;
34 typedef gp_Circ Circ;
35 typedef gp_Dir  Dir;
36 typedef gp_Pnt  Pnt;
37 typedef gp_Trsf Trsf;
38 typedef gp_XYZ  XYZ;
39 typedef gp_Vec  Vec;
40
41
42
43
44 //=======================================================================
45 //function : Copy
46 //purpose  : 
47 //=======================================================================
48
49 Handle(Geom_Geometry) Geom_SphericalSurface::Copy () const {
50  
51   Handle(SphericalSurface) Cs;
52   Cs = new SphericalSurface (pos, radius);
53   return Cs;
54 }
55
56
57
58 //=======================================================================
59 //function : Geom_SphericalSurface
60 //purpose  : 
61 //=======================================================================
62
63 Geom_SphericalSurface::Geom_SphericalSurface (const Ax3& A, const Standard_Real R) 
64 : radius (R) {
65
66   if (R < 0.0) Standard_ConstructionError::Raise();
67   pos = A;
68 }
69
70
71 //=======================================================================
72 //function : Geom_SphericalSurface
73 //purpose  : 
74 //=======================================================================
75
76 Geom_SphericalSurface::Geom_SphericalSurface (const gp_Sphere& S) 
77  :radius (S.Radius()) {
78
79   pos = S.Position();
80 }
81
82
83
84 //=======================================================================
85 //function : UReversedParameter
86 //purpose  : 
87 //=======================================================================
88
89 Standard_Real Geom_SphericalSurface::UReversedParameter( const Standard_Real U) const
90 {
91   return (2.*M_PI - U);
92 }
93
94 //=======================================================================
95 //function : VReversedParameter
96 //purpose  : 
97 //=======================================================================
98
99 Standard_Real Geom_SphericalSurface::VReversedParameter( const Standard_Real V) const
100 {
101   return (-V);
102 }
103
104
105 //=======================================================================
106 //function : Area
107 //purpose  : 
108 //=======================================================================
109
110 Standard_Real Geom_SphericalSurface::Area () const 
111 {return 4.0 * M_PI * radius * radius;}
112
113 //=======================================================================
114 //function : Radius
115 //purpose  : 
116 //=======================================================================
117
118 Standard_Real Geom_SphericalSurface::Radius () const                  
119 { return radius; }
120
121 //=======================================================================
122 //function : IsUClosed
123 //purpose  : 
124 //=======================================================================
125
126 Standard_Boolean Geom_SphericalSurface::IsUClosed () const           
127 { return Standard_True; }
128
129 //=======================================================================
130 //function : IsVClosed
131 //purpose  : 
132 //=======================================================================
133
134 Standard_Boolean Geom_SphericalSurface::IsVClosed () const            
135 { return Standard_False; }
136
137 //=======================================================================
138 //function : IsUPeriodic
139 //purpose  : 
140 //=======================================================================
141
142 Standard_Boolean Geom_SphericalSurface::IsUPeriodic () const          
143 { return Standard_True; }
144
145 //=======================================================================
146 //function : IsVPeriodic
147 //purpose  : 
148 //=======================================================================
149
150 Standard_Boolean Geom_SphericalSurface::IsVPeriodic () const          
151 { return Standard_False; }
152
153 //=======================================================================
154 //function : SetRadius
155 //purpose  : 
156 //=======================================================================
157
158 void Geom_SphericalSurface::SetRadius (const Standard_Real R) {
159
160   if (R < 0.0) { Standard_ConstructionError::Raise(); }
161   radius = R;
162 }
163
164
165 //=======================================================================
166 //function : SetSphere
167 //purpose  : 
168 //=======================================================================
169
170 void Geom_SphericalSurface::SetSphere (const gp_Sphere& S) {
171
172   radius = S.Radius();
173   pos = S.Position();
174 }
175
176
177 //=======================================================================
178 //function : Bounds
179 //purpose  : 
180 //=======================================================================
181
182 void Geom_SphericalSurface::Bounds (Standard_Real& U1, Standard_Real& U2,
183                                     Standard_Real& V1, Standard_Real& V2) const {
184
185   U1 =       0.0;  
186   U2 =  M_PI * 2.0; 
187   V1 = -M_PI / 2.0;
188   V2 =  M_PI / 2.0;
189 }
190
191
192 //=======================================================================
193 //function : Coefficients
194 //purpose  : 
195 //=======================================================================
196
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 {
201
202    // Dans le repere local de la sphere :
203    // X*X + Y*Y + Z*Z - radius * radius = 0
204
205       Trsf T;
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;
229 }
230
231
232 //=======================================================================
233 //function : D0
234 //purpose  : 
235 //=======================================================================
236
237 void Geom_SphericalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const 
238 {
239   ElSLib::SphereD0(U,V,pos,radius,P);
240 }
241
242
243 //=======================================================================
244 //function : D1
245 //purpose  : 
246 //=======================================================================
247
248 void Geom_SphericalSurface::D1 (const Standard_Real U, const Standard_Real V  , 
249                                       Pnt& P,       Vec& D1U, Vec& D1V
250                                ) const 
251 {
252   ElSLib::SphereD1 (U, V, pos, radius, P ,D1U, D1V);
253 }
254
255
256 //=======================================================================
257 //function : D2
258 //purpose  : 
259 //=======================================================================
260
261 void Geom_SphericalSurface::D2 (const Standard_Real U, const Standard_Real V,
262                                 Pnt& P,
263                                 Vec& D1U, Vec& D1V, 
264                                 Vec& D2U, Vec& D2V, Vec& D2UV ) const
265 {
266   ElSLib::SphereD2 (U, V, pos, radius, P, D1U, D1V, D2U, D2V, D2UV);
267 }
268
269
270 //=======================================================================
271 //function : D3
272 //purpose  : 
273 //=======================================================================
274
275 void Geom_SphericalSurface::D3 (const Standard_Real U, const Standard_Real V, 
276                                 Pnt& P,
277                                 Vec& D1U, Vec& D1V, 
278                                 Vec& D2U, Vec& D2V, Vec& D2UV,
279                                 Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV
280                                ) const
281 {
282   ElSLib::SphereD3 (U, V, pos, radius, P, D1U, D1V, D2U, D2V,
283                     D2UV, D3U, D3V, D3UUV, D3UVV);
284 }
285
286
287 //=======================================================================
288 //function : DN
289 //purpose  : 
290 //=======================================================================
291
292 Vec Geom_SphericalSurface::DN (const Standard_Real U, const Standard_Real V, 
293                                const Standard_Integer Nu, const Standard_Integer Nv) const {
294
295    Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, " ");
296    return  ElSLib::SphereDN (U, V, pos, radius, Nu, Nv);
297 }
298
299
300 //=======================================================================
301 //function : Sphere
302 //purpose  : 
303 //=======================================================================
304
305 gp_Sphere Geom_SphericalSurface::Sphere () const {
306
307   return gp_Sphere (pos, radius);
308 }
309
310
311 //=======================================================================
312 //function : UIso
313 //purpose  : 
314 //=======================================================================
315
316 Handle(Curve) Geom_SphericalSurface::UIso (const Standard_Real U) const 
317 {
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);
320   return iso;
321 }
322
323
324 //=======================================================================
325 //function : VIso
326 //purpose  : 
327 //=======================================================================
328
329 Handle(Curve) Geom_SphericalSurface::VIso (const Standard_Real V) const 
330 {
331   Handle(Geom_Circle) 
332     GC = new Geom_Circle(ElSLib::SphereVIso(pos,radius,V));
333   return GC;
334 }
335
336
337 //=======================================================================
338 //function : Volume
339 //purpose  : 
340 //=======================================================================
341
342 Standard_Real Geom_SphericalSurface::Volume () const {
343
344    return (4.0 * M_PI * radius * radius * radius)/3.0;
345 }
346
347
348
349 //=======================================================================
350 //function : Transform
351 //purpose  : 
352 //=======================================================================
353
354 void Geom_SphericalSurface::Transform (const Trsf& T) {
355
356    radius = radius * Abs(T.ScaleFactor());
357    pos.Transform (T);
358 }