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.
19 #include <Geom_Circle.hxx>
20 #include <Geom_Curve.hxx>
21 #include <Geom_Geometry.hxx>
22 #include <Geom_SphericalSurface.hxx>
23 #include <Geom_TrimmedCurve.hxx>
25 #include <gp_Circ.hxx>
27 #include <gp_Sphere.hxx>
28 #include <gp_Trsf.hxx>
31 #include <Standard_ConstructionError.hxx>
32 #include <Standard_RangeError.hxx>
33 #include <Standard_Type.hxx>
35 IMPLEMENT_STANDARD_RTTIEXT(Geom_SphericalSurface,Geom_ElementarySurface)
37 typedef Geom_Circle Circle;
38 typedef Geom_SphericalSurface SphericalSurface;
48 //=======================================================================
51 //=======================================================================
53 Handle(Geom_Geometry) Geom_SphericalSurface::Copy () const {
55 Handle(Geom_SphericalSurface) Cs;
56 Cs = new SphericalSurface (pos, radius);
62 //=======================================================================
63 //function : Geom_SphericalSurface
65 //=======================================================================
67 Geom_SphericalSurface::Geom_SphericalSurface (const Ax3& A, const Standard_Real R)
70 if (R < 0.0) throw Standard_ConstructionError();
75 //=======================================================================
76 //function : Geom_SphericalSurface
78 //=======================================================================
80 Geom_SphericalSurface::Geom_SphericalSurface (const gp_Sphere& S)
81 :radius (S.Radius()) {
88 //=======================================================================
89 //function : UReversedParameter
91 //=======================================================================
93 Standard_Real Geom_SphericalSurface::UReversedParameter( const Standard_Real U) const
98 //=======================================================================
99 //function : VReversedParameter
101 //=======================================================================
103 Standard_Real Geom_SphericalSurface::VReversedParameter( const Standard_Real V) const
109 //=======================================================================
112 //=======================================================================
114 Standard_Real Geom_SphericalSurface::Area () const
115 {return 4.0 * M_PI * radius * radius;}
117 //=======================================================================
120 //=======================================================================
122 Standard_Real Geom_SphericalSurface::Radius () const
125 //=======================================================================
126 //function : IsUClosed
128 //=======================================================================
130 Standard_Boolean Geom_SphericalSurface::IsUClosed () const
131 { return Standard_True; }
133 //=======================================================================
134 //function : IsVClosed
136 //=======================================================================
138 Standard_Boolean Geom_SphericalSurface::IsVClosed () const
139 { return Standard_False; }
141 //=======================================================================
142 //function : IsUPeriodic
144 //=======================================================================
146 Standard_Boolean Geom_SphericalSurface::IsUPeriodic () const
147 { return Standard_True; }
149 //=======================================================================
150 //function : IsVPeriodic
152 //=======================================================================
154 Standard_Boolean Geom_SphericalSurface::IsVPeriodic () const
155 { return Standard_False; }
157 //=======================================================================
158 //function : SetRadius
160 //=======================================================================
162 void Geom_SphericalSurface::SetRadius (const Standard_Real R) {
164 if (R < 0.0) { throw Standard_ConstructionError(); }
169 //=======================================================================
170 //function : SetSphere
172 //=======================================================================
174 void Geom_SphericalSurface::SetSphere (const gp_Sphere& S) {
181 //=======================================================================
184 //=======================================================================
186 void Geom_SphericalSurface::Bounds (Standard_Real& U1, Standard_Real& U2,
187 Standard_Real& V1, Standard_Real& V2) const {
196 //=======================================================================
197 //function : Coefficients
199 //=======================================================================
201 void Geom_SphericalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
202 Standard_Real& B1, Standard_Real& B2, Standard_Real& B3,
203 Standard_Real& C1, Standard_Real& C2, Standard_Real& C3,
204 Standard_Real& D ) const {
206 // Dans le repere local de la sphere :
207 // X*X + Y*Y + Z*Z - radius * radius = 0
210 T.SetTransformation (pos);
211 Standard_Real T11 = T.Value (1, 1);
212 Standard_Real T12 = T.Value (1, 2);
213 Standard_Real T13 = T.Value (1, 3);
214 Standard_Real T14 = T.Value (1, 4);
215 Standard_Real T21 = T.Value (2, 1);
216 Standard_Real T22 = T.Value (2, 2);
217 Standard_Real T23 = T.Value (2, 3);
218 Standard_Real T24 = T.Value (2, 4);
219 Standard_Real T31 = T.Value (3, 1);
220 Standard_Real T32 = T.Value (3, 2);
221 Standard_Real T33 = T.Value (3, 3);
222 Standard_Real T34 = T.Value (3, 4);
223 A1 = T11 * T11 + T21 * T21 + T31 * T31;
224 A2 = T12 * T12 + T22 * T22 + T32 * T32;
225 A3 = T13 * T13 + T23 * T23 + T33 * T33;
226 B1 = T11 * T12 + T21 * T22 + T31 * T32;
227 B2 = T11 * T13 + T21 * T23 + T31 * T33;
228 B3 = T12 * T13 + T22 * T23 + T32 * T33;
229 C1 = T11 * T14 + T21 * T24 + T31 * T34;
230 C2 = T12 * T14 + T22 * T24 + T32 * T34;
231 C3 = T13 * T14 + T23 * T24 + T33 * T34;
232 D = T14 * T14 + T24 * T24 + T34 * T34 - radius * radius;
236 //=======================================================================
239 //=======================================================================
241 void Geom_SphericalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const
243 ElSLib::SphereD0(U,V,pos,radius,P);
247 //=======================================================================
250 //=======================================================================
252 void Geom_SphericalSurface::D1 (const Standard_Real U, const Standard_Real V ,
253 Pnt& P, Vec& D1U, Vec& D1V
256 ElSLib::SphereD1 (U, V, pos, radius, P ,D1U, D1V);
260 //=======================================================================
263 //=======================================================================
265 void Geom_SphericalSurface::D2 (const Standard_Real U, const Standard_Real V,
268 Vec& D2U, Vec& D2V, Vec& D2UV ) const
270 ElSLib::SphereD2 (U, V, pos, radius, P, D1U, D1V, D2U, D2V, D2UV);
274 //=======================================================================
277 //=======================================================================
279 void Geom_SphericalSurface::D3 (const Standard_Real U, const Standard_Real V,
282 Vec& D2U, Vec& D2V, Vec& D2UV,
283 Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV
286 ElSLib::SphereD3 (U, V, pos, radius, P, D1U, D1V, D2U, D2V,
287 D2UV, D3U, D3V, D3UUV, D3UVV);
291 //=======================================================================
294 //=======================================================================
296 Vec Geom_SphericalSurface::DN (const Standard_Real U, const Standard_Real V,
297 const Standard_Integer Nu, const Standard_Integer Nv) const {
299 Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, " ");
300 return ElSLib::SphereDN (U, V, pos, radius, Nu, Nv);
304 //=======================================================================
307 //=======================================================================
309 gp_Sphere Geom_SphericalSurface::Sphere () const {
311 return gp_Sphere (pos, radius);
315 //=======================================================================
318 //=======================================================================
320 Handle(Geom_Curve) Geom_SphericalSurface::UIso (const Standard_Real U) const
322 Handle(Geom_Circle) GC = new Geom_Circle(ElSLib::SphereUIso(pos,radius,U));
323 Handle(Geom_TrimmedCurve) iso = new Geom_TrimmedCurve(GC,-M_PI/2.,M_PI/2);
328 //=======================================================================
331 //=======================================================================
333 Handle(Geom_Curve) Geom_SphericalSurface::VIso (const Standard_Real V) const
336 GC = new Geom_Circle(ElSLib::SphereVIso(pos,radius,V));
341 //=======================================================================
344 //=======================================================================
346 Standard_Real Geom_SphericalSurface::Volume () const {
348 return (4.0 * M_PI * radius * radius * radius)/3.0;
353 //=======================================================================
354 //function : Transform
356 //=======================================================================
358 void Geom_SphericalSurface::Transform (const Trsf& T) {
360 radius = radius * Abs(T.ScaleFactor());