Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Geom / Geom_ConicalSurface.cxx
1 // File:        Geom_ConicalSurface.cxx
2 // Created:     Wed Mar 10 09:33:39 1993
3 // Author:      JCV
4 //              <fid@phylox>
5 // Copyright:   Matra Datavision 1993
6
7 //File Geom_ConicalSurface.cxx, JCV 17/01/91
8
9
10 #include <Geom_ConicalSurface.ixx>
11
12 #include <Standard_ConstructionError.hxx>
13 #include <Standard_RangeError.hxx>
14
15 #include <Precision.hxx>
16 #include <gp.hxx>
17 #include <gp_Lin.hxx>
18 #include <gp_Circ.hxx>
19 #include <gp_Ax2d.hxx>
20 #include <gp_XYZ.hxx>
21 #include <gp_Dir.hxx>
22 #include <ElSLib.hxx>
23 #include <GeomAbs_UVSense.hxx>
24 #include <Geom_Line.hxx>
25 #include <Geom_Circle.hxx>
26
27 typedef Geom_ConicalSurface         ConicalSurface;
28 typedef Handle(Geom_ConicalSurface) Handle(ConicalSurface);
29 typedef gp_Ax1  Ax1;
30 typedef gp_Ax2  Ax2;
31 typedef gp_Ax3  Ax3;
32 typedef gp_Circ Circ;
33 typedef gp_Dir  Dir;
34 typedef gp_Lin  Lin;
35 typedef gp_Pnt  Pnt;
36 typedef gp_Trsf Trsf;
37 typedef gp_Vec  Vec;
38 typedef gp_XYZ  XYZ;
39
40
41
42
43 //=======================================================================
44 //function : Copy
45 //purpose  : 
46 //=======================================================================
47
48 Handle(Geom_Geometry) Geom_ConicalSurface::Copy () const {
49  
50    Handle(ConicalSurface) Cs;
51    Cs = new ConicalSurface (pos, semiAngle, radius);
52    return Cs;
53 }
54
55 //=======================================================================
56 //function : Geom_ConicalSurface
57 //purpose  : 
58 //=======================================================================
59
60 Geom_ConicalSurface::Geom_ConicalSurface ( const Ax3& A3 , 
61                                            const Standard_Real Ang, 
62                                            const Standard_Real R) :
63        radius(R), semiAngle (Ang) 
64 {
65
66   if (R < 0.0 || Abs(Ang) <= gp::Resolution() || Abs(Ang) >= PI/2.0 - gp::Resolution()) 
67     Standard_ConstructionError::Raise();
68   
69   pos = A3;
70 }
71
72
73 //=======================================================================
74 //function : Geom_ConicalSurface
75 //purpose  : 
76 //=======================================================================
77
78 Geom_ConicalSurface::Geom_ConicalSurface ( const gp_Cone& C ) 
79 : radius (C.RefRadius()), semiAngle (C.SemiAngle()) 
80 {
81    pos = C.Position();
82 }
83
84
85 //=======================================================================
86 //function : UReversedParameter
87 //purpose  : 
88 //=======================================================================
89
90 Standard_Real Geom_ConicalSurface::UReversedParameter( const Standard_Real U) const
91 {
92   return ( 2.*PI - U);
93 }
94
95
96 //=======================================================================
97 //function : VReversedParameter
98 //purpose  : 
99 //=======================================================================
100
101 Standard_Real Geom_ConicalSurface::VReversedParameter( const Standard_Real V) const
102 {
103   return ( -V);
104 }
105
106 //=======================================================================
107 //function : VReverse
108 //purpose  : 
109 //=======================================================================
110
111 void Geom_ConicalSurface::VReverse()
112 {
113   semiAngle = -semiAngle;
114   pos.ZReverse();
115 }
116
117 //=======================================================================
118 //function : RefRadius
119 //purpose  : 
120 //=======================================================================
121
122 Standard_Real Geom_ConicalSurface::RefRadius () const               
123 { return radius; }
124
125 //=======================================================================
126 //function : SemiAngle
127 //purpose  : 
128 //=======================================================================
129
130 Standard_Real Geom_ConicalSurface::SemiAngle () const               
131 { return semiAngle;}
132
133 //=======================================================================
134 //function : IsUClosed
135 //purpose  : 
136 //=======================================================================
137
138 Standard_Boolean Geom_ConicalSurface::IsUClosed () const            
139 { return Standard_True; }
140
141 //=======================================================================
142 //function : IsVClosed
143 //purpose  : 
144 //=======================================================================
145
146 Standard_Boolean Geom_ConicalSurface::IsVClosed () const            
147 { return Standard_False; }
148
149 //=======================================================================
150 //function : IsUPeriodic
151 //purpose  : 
152 //=======================================================================
153
154 Standard_Boolean Geom_ConicalSurface::IsUPeriodic () const          
155 { return Standard_True; }
156
157 //=======================================================================
158 //function : IsVPeriodic
159 //purpose  : 
160 //=======================================================================
161
162 Standard_Boolean Geom_ConicalSurface::IsVPeriodic () const          
163 { return Standard_False; }
164
165 //=======================================================================
166 //function : Cone
167 //purpose  : 
168 //=======================================================================
169
170 gp_Cone Geom_ConicalSurface::Cone () const {
171
172   return gp_Cone (pos, semiAngle, radius);
173 }
174
175
176 //=======================================================================
177 //function : SetCone
178 //purpose  : 
179 //=======================================================================
180
181 void Geom_ConicalSurface::SetCone (const gp_Cone& C) {
182
183   radius = C.RefRadius ();
184   semiAngle   = C.SemiAngle ();
185   pos    = C.Position  ();
186 }
187
188
189 //=======================================================================
190 //function : SetRadius
191 //purpose  : 
192 //=======================================================================
193
194 void Geom_ConicalSurface::SetRadius (const Standard_Real R) {
195
196   if (R < 0.0)  Standard_ConstructionError::Raise();
197   radius = R;
198 }
199
200
201 //=======================================================================
202 //function : SetSemiAngle
203 //purpose  : 
204 //=======================================================================
205
206 void Geom_ConicalSurface::SetSemiAngle (const Standard_Real Ang) {
207
208   if (Abs(Ang) <= gp::Resolution() || Abs(Ang) >= PI/2.0 - gp::Resolution()) {
209     Standard_ConstructionError::Raise();
210   }
211   semiAngle = Ang;
212 }
213
214
215 //=======================================================================
216 //function : Apex
217 //purpose  : 
218 //=======================================================================
219
220 Pnt Geom_ConicalSurface::Apex () const 
221 {
222
223    XYZ Coord = Position().Direction().XYZ();
224    Coord.Multiply (-radius / Tan (semiAngle));
225    Coord.Add      (Position().Location().XYZ());
226    return Pnt     (Coord);
227 }
228
229
230 //=======================================================================
231 //function : Bounds
232 //purpose  : 
233 //=======================================================================
234
235 void Geom_ConicalSurface::Bounds (Standard_Real& U1, Standard_Real& U2, 
236                                   Standard_Real& V1, Standard_Real& V2) const {
237
238    U1 = 0.0;  U2 = 2.0 * PI;  
239    V1 = -Precision::Infinite();  V2 = Precision::Infinite();
240 }
241
242
243 //=======================================================================
244 //function : Coefficients
245 //purpose  : 
246 //=======================================================================
247
248 void Geom_ConicalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
249                                         Standard_Real& B1, Standard_Real& B2, Standard_Real& B3,
250                                         Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, 
251                                         Standard_Real& D)  const 
252 {
253    // Dans le repere du cone :
254    // X**2 + Y**2 - (Myradius - Z * Tan(semiAngle))**2 = 0.0
255
256       Trsf T;
257       T.SetTransformation (pos);
258       Standard_Real KAng = Tan (semiAngle);
259       Standard_Real T11 = T.Value (1, 1);
260       Standard_Real T12 = T.Value (1, 2);
261       Standard_Real T13 = T.Value (1, 3);
262       Standard_Real T14 = T.Value (1, 4);
263       Standard_Real T21 = T.Value (2, 1);
264       Standard_Real T22 = T.Value (2, 2);
265       Standard_Real T23 = T.Value (2, 3);
266       Standard_Real T24 = T.Value (2, 4);
267       Standard_Real T31 = T.Value (3, 1) * KAng;
268       Standard_Real T32 = T.Value (3, 2) * KAng;
269       Standard_Real T33 = T.Value (3, 3) * KAng;
270       Standard_Real T34 = T.Value (3, 4) * KAng;
271       A1 = T11 * T11 + T21 * T21 - T31 * T31;
272       A2 = T12 * T12 + T22 * T22 - T32 * T32;
273       A3 = T13 * T13 + T23 * T23 - T33 * T33;
274       B1 = T11 * T12 + T21 * T22 - T31 * T32;
275       B2 = T11 * T13 + T21 * T23 - T31 * T33;
276       B3 = T12 * T13 + T22 * T23 - T32 * T33;
277       C1 = T11 * T14 + T21 * T24 + radius * T31;
278       C2 = T12 * T14 + T22 * T24 + radius * T32;
279       C3 = T13 * T14 + T23 * T24 + radius * T33;
280       D = T14 * T14 + T24 * T24 - radius * radius - T34 * T34 +
281           2.0 * radius * T34;  
282 }
283
284
285
286 //=======================================================================
287 //function : D0
288 //purpose  : 
289 //=======================================================================
290
291 void Geom_ConicalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const 
292 {
293
294   P = ElSLib::ConeValue (U, V, pos, radius, semiAngle);
295 }
296
297
298 //=======================================================================
299 //function : D1
300 //purpose  : 
301 //=======================================================================
302
303 void Geom_ConicalSurface::D1 (const Standard_Real U  , const Standard_Real V, 
304                                     Pnt& P  , 
305                                     Vec& D1U, Vec& D1V     ) const 
306 {
307   ElSLib::ConeD1 (U, V, pos, radius, semiAngle, P, D1U, D1V);
308 }
309
310
311 //=======================================================================
312 //function : D2
313 //purpose  : 
314 //=======================================================================
315
316 void Geom_ConicalSurface::D2 ( const Standard_Real U  , const Standard_Real V, 
317                                      Pnt& P  ,  
318                                      Vec& D1U, Vec& D1V, 
319                                      Vec& D2U, Vec& D2V, Vec& D2UV) const 
320 {
321   ElSLib::ConeD2 (U, V, pos, radius, semiAngle, P, D1U, D1V, 
322                   D2U, D2V, D2UV);
323 }
324
325
326 //=======================================================================
327 //function : D3
328 //purpose  : 
329 //=======================================================================
330
331 void Geom_ConicalSurface::D3 (const Standard_Real U, const Standard_Real V, 
332                               Pnt& P      , 
333                               Vec& D1U    , Vec& D1V,
334                               Vec& D2U    , Vec& D2V, Vec& D2UV,
335                               Vec& D3U    , Vec& D3V, Vec& D3UUV, Vec& D3UVV
336                               ) const
337 {
338   ElSLib::ConeD3 (U, V, pos, radius, semiAngle, P, D1U, D1V, D2U, D2V,
339                   D2UV, D3U, D3V, D3UUV, D3UVV);
340 }
341
342
343 //=======================================================================
344 //function : DN
345 //purpose  : 
346 //=======================================================================
347
348 Vec Geom_ConicalSurface::DN (const Standard_Real    U , const Standard_Real     V, 
349                              const Standard_Integer Nu, const Standard_Integer Nv ) const
350 {
351   Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv < 0, " ");
352   if (Nv > 1) { return Vec (0.0, 0.0, 0.0); }
353   else {
354     return ElSLib::ConeDN (U, V, pos, radius, semiAngle, Nu, Nv);
355   }
356 }
357
358
359 //=======================================================================
360 //function : UIso
361 //purpose  : 
362 //=======================================================================
363
364 Handle(Geom_Curve) Geom_ConicalSurface::UIso (const Standard_Real U) const 
365 {
366   Handle(Geom_Line) 
367     GL = new Geom_Line(ElSLib::ConeUIso(pos,radius,semiAngle,U));
368   return GL;
369 }
370
371
372 //=======================================================================
373 //function : VIso
374 //purpose  : 
375 //=======================================================================
376
377 Handle(Geom_Curve) Geom_ConicalSurface::VIso (const Standard_Real V) const 
378 {
379   Handle(Geom_Circle) 
380     GC = new Geom_Circle(ElSLib::ConeVIso(pos,radius,semiAngle,V));
381   return GC;
382 }
383
384
385 //=======================================================================
386 //function : Transform
387 //purpose  : 
388 //=======================================================================
389
390 void Geom_ConicalSurface::Transform (const Trsf& T) 
391 {
392   radius = radius * Abs(T.ScaleFactor());
393   pos.Transform (T);
394 }
395
396 //=======================================================================
397 //function : TransformParameters
398 //purpose  : 
399 //=======================================================================
400
401 void Geom_ConicalSurface::TransformParameters(Standard_Real& ,
402                                               Standard_Real& V,
403                                               const gp_Trsf& T) 
404 const
405 {
406   if (!Precision::IsInfinite(V)) V *= Abs(T.ScaleFactor());
407 }
408
409 //=======================================================================
410 //function : ParametricTransformation
411 //purpose  : 
412 //=======================================================================
413
414 gp_GTrsf2d Geom_ConicalSurface::ParametricTransformation(const gp_Trsf& T)
415 const
416 {
417   gp_GTrsf2d T2;
418   gp_Ax2d Axis(gp::Origin2d(),gp::DX2d());
419   T2.SetAffinity(Axis, Abs(T.ScaleFactor()));
420   return T2;
421 }
422