0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / ElCLib / ElCLib.cxx
1 // Created on: 1991-09-09
2 // Created by: Michel Chauvat
3 // Copyright (c) 1991-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 // Evolutions   JCV Dec 1991 ajout de calculs de derivees et traitement
18 //              d'entites 2d
19 //              JCV Mars 1992 ajout method SetLinearForm
20
21 #define No_Standard_OutOfRange
22
23
24 #include <ElCLib.hxx>
25 #include <gp.hxx>
26 #include <gp_Ax1.hxx>
27 #include <gp_Ax2.hxx>
28 #include <gp_Ax2d.hxx>
29 #include <gp_Ax22d.hxx>
30 #include <gp_Circ.hxx>
31 #include <gp_Circ2d.hxx>
32 #include <gp_Dir.hxx>
33 #include <gp_Dir2d.hxx>
34 #include <gp_Elips.hxx>
35 #include <gp_Elips2d.hxx>
36 #include <gp_Hypr.hxx>
37 #include <gp_Hypr2d.hxx>
38 #include <gp_Lin.hxx>
39 #include <gp_Lin2d.hxx>
40 #include <gp_Parab.hxx>
41 #include <gp_Parab2d.hxx>
42 #include <gp_Pnt.hxx>
43 #include <gp_Pnt2d.hxx>
44 #include <gp_Vec.hxx>
45 #include <gp_Vec2d.hxx>
46
47 static Standard_Real PIPI = M_PI + M_PI;
48
49 //=======================================================================
50 //function : InPeriod
51 //purpose  : Value theULast is never returned.
52 //          Example of some case (checked on WIN64 platform)
53 //          with some surface having period 2*PI = 6.2831853071795862.
54 //            Let theUFirst be equal to 6.1645624650899675. Then,
55 //          theULast must be equal to
56 //              6.1645624650899675+6.2831853071795862=12.4477477722695537.
57 //
58 //          However, real result is 12.447747772269555.
59 //          Therefore, new period value to adjust will be equal to
60 //              12.447747772269555-6.1645624650899675=6.2831853071795871.
61 //
62 //          As we can see, (6.2831853071795871 != 6.2831853071795862).
63 //
64 //          According to above said, this method should be used carefully.
65 //          In order to increase reliability of this method, input arguments
66 //          needs to be replaced with following: 
67 //            (theU, theUFirst, thePeriod). theULast parameter is excess.
68 //=======================================================================
69 Standard_Real  ElCLib::InPeriod(const Standard_Real theU, 
70                                 const Standard_Real theUFirst, 
71                                 const Standard_Real theULast)
72 {
73   if( Precision::IsInfinite(theU) ||
74       Precision::IsInfinite(theUFirst) ||
75       Precision::IsInfinite(theULast))
76   {//In order to avoid FLT_Overflow exception
77     return theU;
78   }
79
80   const Standard_Real aPeriod = theULast - theUFirst;
81
82   if(aPeriod < Epsilon(theULast))
83     return theU;
84
85   return Max(theUFirst, theU + aPeriod*Ceiling((theUFirst-theU)/aPeriod));
86 }
87
88 //=======================================================================
89 //function : AdjustPeriodic
90 //purpose  : 
91 //=======================================================================
92
93 void ElCLib::AdjustPeriodic(const Standard_Real UFirst,
94                             const Standard_Real ULast,
95                             const Standard_Real Preci,
96                             Standard_Real& U1,
97                             Standard_Real& U2)
98 {
99   if (Precision::IsInfinite(UFirst) ||
100       Precision::IsInfinite(ULast))
101   {
102     U1 = UFirst;
103     U2 = ULast;
104     return;
105   }
106   
107   Standard_Real period = ULast - UFirst;
108
109   if (period < Epsilon(ULast))
110   {
111     // In order to avoid FLT_Overflow exception
112     // (test bugs moddata_1 bug22757)
113     U1 = UFirst;
114     U2 = ULast;
115     return;
116   }
117
118   U1 -= Floor((U1-UFirst)/period) * period;
119   if (ULast - U1 < Preci) U1 -= period;
120   U2 -= Floor((U2-U1)/period) * period;
121   if (U2 - U1 < Preci) U2 += period;
122 }
123
124 //=======================================================================
125 //function : LineValue
126 //purpose  : 
127 //=======================================================================
128
129 gp_Pnt ElCLib::LineValue (const Standard_Real U,
130                           const gp_Ax1& Pos)
131 {
132   const gp_XYZ& ZDir = Pos.Direction().XYZ();
133   const gp_XYZ& PLoc = Pos.Location ().XYZ();
134   return gp_Pnt(U * ZDir.X() + PLoc.X(),
135                 U * ZDir.Y() + PLoc.Y(),
136                 U * ZDir.Z() + PLoc.Z());
137 }
138
139 //=======================================================================
140 //function : CircleValue
141 //purpose  : 
142 //=======================================================================
143
144 gp_Pnt ElCLib::CircleValue (const Standard_Real U,
145                             const gp_Ax2& Pos,
146                             const Standard_Real Radius)
147 {
148   const gp_XYZ& XDir = Pos.XDirection().XYZ();
149   const gp_XYZ& YDir = Pos.YDirection().XYZ();
150   const gp_XYZ& PLoc = Pos.Location  ().XYZ();
151   Standard_Real A1 = Radius * cos(U);
152   Standard_Real A2 = Radius * sin(U);
153   return gp_Pnt(A1 * XDir.X() + A2 * YDir.X() + PLoc.X(),
154                 A1 * XDir.Y() + A2 * YDir.Y() + PLoc.Y(),
155                 A1 * XDir.Z() + A2 * YDir.Z() + PLoc.Z());
156 }
157
158 //=======================================================================
159 //function : EllipseValue
160 //purpose  : 
161 //=======================================================================
162
163 gp_Pnt ElCLib::EllipseValue (const Standard_Real U,
164                              const gp_Ax2& Pos, 
165                              const Standard_Real MajorRadius,
166                              const Standard_Real MinorRadius)
167 {
168   const gp_XYZ& XDir = Pos.XDirection().XYZ();
169   const gp_XYZ& YDir = Pos.YDirection().XYZ();
170   const gp_XYZ& PLoc = Pos.Location  ().XYZ();
171   Standard_Real A1 = MajorRadius * cos(U);
172   Standard_Real A2 = MinorRadius * sin(U);
173   return gp_Pnt(A1 * XDir.X() + A2 * YDir.X() + PLoc.X(),
174                 A1 * XDir.Y() + A2 * YDir.Y() + PLoc.Y(),
175                 A1 * XDir.Z() + A2 * YDir.Z() + PLoc.Z());
176 }
177
178 //=======================================================================
179 //function : HyperbolaValue
180 //purpose  : 
181 //=======================================================================
182
183 gp_Pnt ElCLib::HyperbolaValue (const Standard_Real U,
184                                const gp_Ax2& Pos,
185                                const Standard_Real MajorRadius,
186                                const Standard_Real MinorRadius)
187 {
188   const gp_XYZ& XDir = Pos.XDirection().XYZ();
189   const gp_XYZ& YDir = Pos.YDirection().XYZ();
190   const gp_XYZ& PLoc = Pos.Location  ().XYZ();
191   Standard_Real A1 = MajorRadius * Cosh(U);
192   Standard_Real A2 = MinorRadius * Sinh(U);
193   return gp_Pnt(A1 * XDir.X() + A2 * YDir.X() + PLoc.X(),
194                 A1 * XDir.Y() + A2 * YDir.Y() + PLoc.Y(),
195                 A1 * XDir.Z() + A2 * YDir.Z() + PLoc.Z());
196 }
197
198 //=======================================================================
199 //function : ParabolaValue
200 //purpose  : 
201 //=======================================================================
202
203 gp_Pnt ElCLib::ParabolaValue (const Standard_Real U,
204                               const gp_Ax2& Pos,
205                               const Standard_Real Focal)
206 {
207   if (Focal == 0.0) {
208     const gp_XYZ& XDir = Pos.XDirection().XYZ();
209     const gp_XYZ& PLoc = Pos.Location  ().XYZ();
210     return gp_Pnt(U * XDir.X() + PLoc.X(),
211                   U * XDir.Y() + PLoc.Y(),
212                   U * XDir.Z() + PLoc.Z());
213   }
214   const gp_XYZ& XDir = Pos.XDirection().XYZ();
215   const gp_XYZ& YDir = Pos.YDirection().XYZ();
216   const gp_XYZ& PLoc = Pos.Location  ().XYZ();
217   Standard_Real A1 = U * U / (4.0 * Focal);
218   return gp_Pnt(A1 * XDir.X() + U * YDir.X() + PLoc.X(),
219                 A1 * XDir.Y() + U * YDir.Y() + PLoc.Y(),
220                 A1 * XDir.Z() + U * YDir.Z() + PLoc.Z());
221 }
222
223 //=======================================================================
224 //function : LineD1
225 //purpose  : 
226 //=======================================================================
227
228 void ElCLib::LineD1 (const Standard_Real U,
229                      const gp_Ax1& Pos,
230                      gp_Pnt& P,
231                      gp_Vec& V1)
232 {
233   gp_XYZ Coord = Pos.Direction().XYZ();
234   V1.SetXYZ (Coord);
235   Coord.SetLinearForm (U, Coord, Pos.Location().XYZ());
236   P.SetXYZ (Coord);
237 }
238
239 //=======================================================================
240 //function : CircleD1
241 //purpose  : 
242 //=======================================================================
243
244 void ElCLib::CircleD1 (const Standard_Real U,
245                        const gp_Ax2& Pos,
246                        const Standard_Real Radius, 
247                        gp_Pnt& P,
248                        gp_Vec& V1)
249 {
250   Standard_Real Xc = Radius * Cos (U);
251   Standard_Real Yc = Radius * Sin (U);
252   gp_XYZ Coord0;
253   gp_XYZ Coord1 (Pos.XDirection().XYZ());
254   gp_XYZ Coord2 (Pos.YDirection().XYZ());
255   //Point courant :
256   Coord0.SetLinearForm (Xc, Coord1, Yc, Coord2, Pos.Location().XYZ());
257   P.SetXYZ (Coord0);
258   //D1 :
259   Coord0.SetLinearForm (-Yc, Coord1, Xc, Coord2);
260   V1.SetXYZ (Coord0);
261 }
262
263 //=======================================================================
264 //function : EllipseD1
265 //purpose  : 
266 //=======================================================================
267
268 void ElCLib::EllipseD1 (const Standard_Real U,
269                         const gp_Ax2& Pos,
270                         const Standard_Real MajorRadius,
271                         const Standard_Real MinorRadius,
272                         gp_Pnt& P,
273                         gp_Vec& V1)
274 {
275   Standard_Real Xc = Cos (U);
276   Standard_Real Yc = Sin (U);
277   gp_XYZ Coord0;
278   gp_XYZ Coord1 (Pos.XDirection().XYZ());
279   gp_XYZ Coord2 (Pos.YDirection().XYZ());
280   //Point courant :
281   Coord0.SetLinearForm (Xc*MajorRadius, Coord1, 
282                         Yc*MinorRadius, Coord2,
283                         Pos.Location().XYZ());
284   P.SetXYZ (Coord0);
285   //D1 :
286   Coord0.SetLinearForm (-Yc*MajorRadius, Coord1, Xc*MinorRadius, Coord2);
287   V1.SetXYZ (Coord0);
288 }
289
290 //=======================================================================
291 //function : HyperbolaD1
292 //purpose  : 
293 //=======================================================================
294
295 void ElCLib::HyperbolaD1 (const Standard_Real U,
296                           const gp_Ax2& Pos,
297                           const Standard_Real MajorRadius,
298                           const Standard_Real MinorRadius, 
299                           gp_Pnt& P,
300                           gp_Vec& V1)
301 {
302   Standard_Real Xc = Cosh (U);
303   Standard_Real Yc = Sinh (U);
304   gp_XYZ Coord0;
305   gp_XYZ Coord1 (Pos.XDirection().XYZ());
306   gp_XYZ Coord2 (Pos.YDirection().XYZ());
307   //Point courant :
308   Coord0.SetLinearForm (Xc*MajorRadius, Coord1, 
309                         Yc*MinorRadius, Coord2,
310                         Pos.Location().XYZ());
311   P.SetXYZ (Coord0);
312   //D1 :
313   Coord0.SetLinearForm (Yc*MajorRadius, Coord1, Xc*MinorRadius, Coord2);
314   V1.SetXYZ (Coord0);
315 }
316
317 //=======================================================================
318 //function : ParabolaD1
319 //purpose  : 
320 //=======================================================================
321
322 void ElCLib::ParabolaD1 (const Standard_Real U,
323                          const gp_Ax2& Pos,
324                          const Standard_Real Focal,
325                          gp_Pnt& P,
326                          gp_Vec& V1)
327 {
328   gp_XYZ Coord0;
329   gp_XYZ Coord1 (Pos.XDirection().XYZ());
330   if (Focal == 0.0) {      //Parabole degenere en une droite
331     V1.SetXYZ (Coord1);
332     Coord1.Multiply (U);
333     Coord1.Add (Pos.Location().XYZ());
334     P.SetXYZ (Coord1);
335   }
336   else {
337     gp_XYZ Coord2 (Pos.YDirection().XYZ());
338     Coord0.SetLinearForm (U / (2.0 * Focal), Coord1, Coord2);
339     V1.SetXYZ (Coord0);
340     Coord0.SetLinearForm ((U * U) / (4.0 * Focal), Coord1, 
341                           U, Coord2,
342                           Pos.Location().XYZ());
343     P.SetXYZ (Coord0);
344   }
345 }
346
347 //=======================================================================
348 //function : CircleD2
349 //purpose  : 
350 //=======================================================================
351
352 void ElCLib::CircleD2 (const Standard_Real U,
353                        const gp_Ax2& Pos,
354                        const Standard_Real Radius,
355                        gp_Pnt& P,
356                        gp_Vec& V1,
357                        gp_Vec& V2)
358 {
359   Standard_Real Xc = Radius * cos(U);
360   Standard_Real Yc = Radius * sin(U);
361   gp_XYZ Coord0;
362   gp_XYZ Coord1 (Pos.XDirection().XYZ());
363   gp_XYZ Coord2 (Pos.YDirection().XYZ());
364   //Point courant :
365   Coord0.SetLinearForm (Xc, Coord1, Yc, Coord2, Pos.Location().XYZ());
366   P.SetXYZ (Coord0);
367   //D1 :
368   Coord0.SetLinearForm (-Yc, Coord1, Xc, Coord2);
369   V1.SetXYZ (Coord0);
370   //D2 :
371   Coord0.SetLinearForm (-Xc, Coord1, -Yc, Coord2);
372   V2.SetXYZ (Coord0);
373 }
374
375 //=======================================================================
376 //function : EllipseD2
377 //purpose  : 
378 //=======================================================================
379
380 void ElCLib::EllipseD2 (const Standard_Real U,
381                         const gp_Ax2& Pos,
382                         const Standard_Real MajorRadius,
383                         const Standard_Real MinorRadius,
384                         gp_Pnt& P,
385                         gp_Vec& V1,
386                         gp_Vec& V2)
387 {
388   Standard_Real Xc = cos(U);
389   Standard_Real Yc = sin(U);
390   gp_XYZ Coord0; 
391   gp_XYZ Coord1 (Pos.XDirection().XYZ());
392   gp_XYZ Coord2 (Pos.YDirection().XYZ());
393   //Point courant :
394   Coord0.SetLinearForm (Xc*MajorRadius, Coord1, 
395                         Yc*MinorRadius, Coord2,
396                         Pos.Location().XYZ());
397   P.SetXYZ (Coord0);
398   //D1 :
399   Coord0.SetLinearForm (-Yc*MajorRadius, Coord1, Xc*MinorRadius, Coord2);
400   V1.SetXYZ (Coord0);
401   //D2 :
402   Coord0.SetLinearForm (-Xc*MajorRadius, Coord1, -Yc*MinorRadius, Coord2);
403   V2.SetXYZ (Coord0);
404 }
405
406 //=======================================================================
407 //function : HyperbolaD2
408 //purpose  : 
409 //=======================================================================
410
411 void ElCLib::HyperbolaD2 (const Standard_Real U,
412                           const gp_Ax2& Pos,
413                           const Standard_Real MajorRadius,
414                           const Standard_Real MinorRadius,
415                           gp_Pnt& P,
416                           gp_Vec& V1,
417                           gp_Vec& V2)
418 {
419   Standard_Real Xc = Cosh(U);
420   Standard_Real Yc = Sinh(U);
421   gp_XYZ Coord0; 
422   gp_XYZ Coord1 (Pos.XDirection().XYZ());
423   gp_XYZ Coord2 (Pos.YDirection().XYZ());
424
425   //Point courant et D2:
426   Coord0.SetLinearForm (Xc*MajorRadius, Coord1, Yc*MinorRadius, Coord2);
427   V2.SetXYZ (Coord0);
428   Coord0.Add (Pos.Location().XYZ());
429   P.SetXYZ (Coord0);
430   //D1 :
431   Coord0.SetLinearForm (Yc*MajorRadius, Coord1, Xc*MinorRadius, Coord2);
432   V1.SetXYZ (Coord0);
433 }
434
435 //=======================================================================
436 //function : ParabolaD2
437 //purpose  : 
438 //=======================================================================
439
440 void ElCLib::ParabolaD2 (const Standard_Real U,
441                          const gp_Ax2& Pos,
442                          const Standard_Real Focal,
443                          gp_Pnt& P,
444                          gp_Vec& V1,
445                          gp_Vec& V2)
446 {
447   gp_XYZ Coord0(0.0, 0.0, 0.0);
448   gp_XYZ Coord1 (Pos.XDirection().XYZ());
449   if (Focal == 0.0) {
450     V2.SetCoord (0.0, 0.0, 0.0);
451     V1.SetXYZ (Coord1);
452     Coord1.Multiply (U);
453     Coord1.Add (Pos.Location().XYZ());        
454     P.SetXYZ (Coord1);//was: P.SetXYZ (Coord0);
455     
456   }
457   else {
458     gp_XYZ Coord2 (Pos.YDirection().XYZ());
459     Coord0.SetLinearForm ((U * U) / (4.0 * Focal), Coord1, 
460                           U, Coord2,
461                           Pos.Location().XYZ());
462     P.SetXYZ (Coord0);
463     Coord0.SetLinearForm (U / (2.0 * Focal), Coord1, Coord2);
464     V1.SetXYZ (Coord0);
465     Coord1.Multiply (1.0 / (2.0 * Focal));
466     V2.SetXYZ (Coord1);
467   }
468 }
469
470 //=======================================================================
471 //function : CircleD3
472 //purpose  : 
473 //=======================================================================
474
475 void ElCLib::CircleD3 (const Standard_Real U,
476                        const gp_Ax2& Pos,
477                        const Standard_Real Radius, 
478                        gp_Pnt& P,
479                        gp_Vec& V1,
480                        gp_Vec& V2,
481                        gp_Vec& V3)
482 {
483   Standard_Real Xc = Radius * cos(U);
484   Standard_Real Yc = Radius * sin(U);
485   gp_XYZ Coord0;
486   gp_XYZ Coord1 (Pos.XDirection().XYZ());
487   gp_XYZ Coord2 (Pos.YDirection().XYZ());
488   //Point Courant :
489   Coord0.SetLinearForm (Xc, Coord1, Yc, Coord2, Pos.Location().XYZ());
490   P.SetXYZ (Coord0);
491   //D1 :
492   Coord0.SetLinearForm (-Yc, Coord1, Xc, Coord2);
493   V1.SetXYZ (Coord0);
494   //D2 :
495   Coord0.SetLinearForm (-Xc, Coord1, -Yc, Coord2);
496   V2.SetXYZ (Coord0);
497   //D3 :
498   Coord0.SetLinearForm (Yc, Coord1, -Xc, Coord2);
499   V3.SetXYZ (Coord0);
500 }
501
502 //=======================================================================
503 //function : EllipseD3
504 //purpose  : 
505 //=======================================================================
506
507 void ElCLib::EllipseD3 (const Standard_Real U,
508                         const gp_Ax2& Pos,
509                         const Standard_Real MajorRadius,
510                         const Standard_Real MinorRadius,
511                         gp_Pnt& P,
512                         gp_Vec& V1,
513                         gp_Vec& V2,
514                         gp_Vec& V3)
515 {
516   Standard_Real Xc = cos(U);
517   Standard_Real Yc = sin(U);
518   gp_XYZ Coord0;
519   gp_XYZ Coord1 (Pos.XDirection().XYZ());
520   gp_XYZ Coord2 (Pos.YDirection().XYZ());
521   //Point Courant :
522   Coord0.SetLinearForm (Xc*MajorRadius, Coord1,
523                         Yc*MinorRadius, Coord2,
524                         Pos.Location().XYZ());
525   P.SetXYZ (Coord0);
526   //D1 :
527   Coord0.SetLinearForm (-Yc*MajorRadius, Coord1, Xc*MinorRadius, Coord2);
528   V1.SetXYZ (Coord0);
529   //D2 :
530   Coord0.SetLinearForm (-Xc*MajorRadius, Coord1, -Yc*MinorRadius, Coord2);
531   V2.SetXYZ (Coord0);
532   //D3
533   Coord0.SetLinearForm (Yc*MajorRadius, Coord1, -Xc*MinorRadius, Coord2);
534   V3.SetXYZ (Coord0);
535 }
536
537 //=======================================================================
538 //function : HyperbolaD3
539 //purpose  : 
540 //=======================================================================
541
542 void ElCLib::HyperbolaD3 (const Standard_Real U,
543                           const gp_Ax2& Pos,
544                           const Standard_Real MajorRadius,
545                           const Standard_Real MinorRadius,
546                           gp_Pnt& P,
547                           gp_Vec& V1,
548                           gp_Vec& V2,
549                           gp_Vec& V3)
550 {
551   Standard_Real Xc = Cosh(U);
552   Standard_Real Yc = Sinh(U);
553   gp_XYZ Coord0;
554   gp_XYZ Coord1 (Pos.XDirection().XYZ());
555   gp_XYZ Coord2 (Pos.YDirection().XYZ());
556   //Point courant et D2 :
557   Coord0.SetLinearForm (Xc*MajorRadius, Coord1, Yc*MinorRadius, Coord2);
558   V2.SetXYZ (Coord0);
559   Coord0.Add (Pos.Location().XYZ());
560   P.SetXYZ (Coord0);
561   //D1 et D3 :
562   Coord0.SetLinearForm (Yc*MajorRadius, Coord1, Xc*MinorRadius, Coord2);
563   V1.SetXYZ (Coord0);
564   V3.SetXYZ (Coord0);
565 }
566
567 //=======================================================================
568 //function : LineValue
569 //purpose  : 
570 //=======================================================================
571
572 gp_Pnt2d ElCLib::LineValue (const Standard_Real U,
573                             const gp_Ax2d& Pos)
574 {
575   const gp_XY& ZDir = Pos.Direction().XY();
576   const gp_XY& PLoc = Pos.Location ().XY();
577   return gp_Pnt2d(U * ZDir.X() + PLoc.X(),
578                   U * ZDir.Y() + PLoc.Y());
579 }
580
581 //=======================================================================
582 //function : CircleValue
583 //purpose  : 
584 //=======================================================================
585
586 gp_Pnt2d ElCLib::CircleValue (const Standard_Real U,
587                               const gp_Ax22d& Pos,
588                               const Standard_Real Radius)
589 {
590   const gp_XY& XDir = Pos.XDirection().XY();
591   const gp_XY& YDir = Pos.YDirection().XY();
592   const gp_XY& PLoc = Pos.Location  ().XY();
593   Standard_Real A1 = Radius * cos(U);
594   Standard_Real A2 = Radius * sin(U);
595   return gp_Pnt2d(A1 * XDir.X() + A2 * YDir.X() + PLoc.X(),
596                   A1 * XDir.Y() + A2 * YDir.Y() + PLoc.Y());
597 }
598
599 //=======================================================================
600 //function : EllipseValue
601 //purpose  : 
602 //=======================================================================
603
604 gp_Pnt2d ElCLib::EllipseValue (const Standard_Real U,
605                                const gp_Ax22d& Pos,
606                                const Standard_Real MajorRadius,
607                                const Standard_Real MinorRadius)
608 {
609   const gp_XY& XDir = Pos.XDirection().XY();
610   const gp_XY& YDir = Pos.YDirection().XY();
611   const gp_XY& PLoc = Pos.Location  ().XY();
612   Standard_Real A1 = MajorRadius * cos(U);
613   Standard_Real A2 = MinorRadius * sin(U);
614   return gp_Pnt2d(A1 * XDir.X() + A2 * YDir.X() + PLoc.X(),
615                   A1 * XDir.Y() + A2 * YDir.Y() + PLoc.Y());
616 }
617
618 //=======================================================================
619 //function : HyperbolaValue
620 //purpose  : 
621 //=======================================================================
622
623 gp_Pnt2d ElCLib::HyperbolaValue (const Standard_Real U,
624                                  const gp_Ax22d& Pos,
625                                  const Standard_Real MajorRadius,
626                                  const Standard_Real MinorRadius)
627 {
628   const gp_XY& XDir = Pos.XDirection().XY();
629   const gp_XY& YDir = Pos.YDirection().XY();
630   const gp_XY& PLoc = Pos.Location  ().XY();
631   Standard_Real A1 = MajorRadius * Cosh(U);
632   Standard_Real A2 = MinorRadius * Sinh(U);
633   return gp_Pnt2d(A1 * XDir.X() + A2 * YDir.X() + PLoc.X(),
634                   A1 * XDir.Y() + A2 * YDir.Y() + PLoc.Y());
635 }
636
637 //=======================================================================
638 //function : ParabolaValue
639 //purpose  : 
640 //=======================================================================
641
642 gp_Pnt2d ElCLib::ParabolaValue (const Standard_Real U,
643                                 const gp_Ax22d& Pos,
644                                 const Standard_Real Focal)
645 {
646   if (Focal == 0.0) {
647     const gp_XY& XDir = Pos.XDirection().XY();
648     const gp_XY& PLoc = Pos.Location  ().XY();
649     return gp_Pnt2d(U * XDir.X() + PLoc.X(),
650                     U * XDir.Y() + PLoc.Y());
651   }
652   const gp_XY& XDir = Pos.XDirection().XY();
653   const gp_XY& YDir = Pos.YDirection().XY();
654   const gp_XY& PLoc = Pos.Location  ().XY();
655   Standard_Real A1 = U * U / (4.0 * Focal);
656   return gp_Pnt2d(A1 * XDir.X() + U * YDir.X() + PLoc.X(),
657                   A1 * XDir.Y() + U * YDir.Y() + PLoc.Y());
658 }
659
660 //=======================================================================
661 //function : LineD1
662 //purpose  : 
663 //=======================================================================
664
665 void ElCLib::LineD1(const Standard_Real U,
666                     const gp_Ax2d& Pos,
667                     gp_Pnt2d& P,
668                     gp_Vec2d& V1)
669 {
670   gp_XY Coord = Pos.Direction().XY();
671   V1.SetXY (Coord);
672   Coord.SetLinearForm (U, Coord, Pos.Location().XY());
673   P.SetXY (Coord);
674 }
675
676 //=======================================================================
677 //function : CircleD1
678 //purpose  : 
679 //=======================================================================
680
681 void ElCLib::CircleD1 (const Standard_Real U,
682                        const gp_Ax22d& Pos,
683                        const Standard_Real Radius,
684                        gp_Pnt2d& P,
685                        gp_Vec2d& V1)
686 {
687   gp_XY Vxy;
688   gp_XY Xdir (Pos.XDirection().XY());
689   gp_XY Ydir (Pos.YDirection().XY());
690   Standard_Real Xc = Radius * cos(U);
691   Standard_Real Yc = Radius * sin(U);
692   //Point courant :
693   Vxy.SetLinearForm (Xc, Xdir, Yc, Ydir, Pos.Location().XY());
694   P.SetXY (Vxy);
695   //V1 :
696   Vxy.SetLinearForm (-Yc, Xdir, Xc, Ydir);
697   V1.SetXY (Vxy);
698 }
699
700 //=======================================================================
701 //function : EllipseD1
702 //purpose  : 
703 //=======================================================================
704
705 void ElCLib::EllipseD1 (const Standard_Real U,
706                         const gp_Ax22d& Pos,
707                         const Standard_Real MajorRadius,
708                         const Standard_Real MinorRadius,
709                         gp_Pnt2d& P,
710                         gp_Vec2d& V1)
711 {
712   gp_XY Vxy;
713   gp_XY Xdir ((Pos.XDirection()).XY());
714   gp_XY Ydir ((Pos.YDirection()).XY());
715   Standard_Real Xc = cos(U);
716   Standard_Real Yc = sin(U);
717   //Point courant :
718   Vxy.SetLinearForm (Xc*MajorRadius, Xdir,
719                      Yc*MinorRadius, Ydir,
720                      Pos.Location().XY());
721   P.SetXY (Vxy);
722   
723   //V1 :
724   Vxy.SetLinearForm (-Yc*MajorRadius, Xdir, Xc*MinorRadius, Ydir);
725   V1.SetXY (Vxy);
726 }
727
728 //=======================================================================
729 //function : HyperbolaD1
730 //purpose  : 
731 //=======================================================================
732
733 void ElCLib::HyperbolaD1 (const Standard_Real U,
734                           const gp_Ax22d& Pos,
735                           const Standard_Real MajorRadius,
736                           const Standard_Real MinorRadius,
737                           gp_Pnt2d& P,
738                           gp_Vec2d& V1)
739 {
740   gp_XY Vxy;
741   gp_XY Xdir ((Pos.XDirection()).XY());
742   gp_XY Ydir ((Pos.YDirection()).XY());
743   Standard_Real Xc = Cosh(U);
744   Standard_Real Yc = Sinh(U);
745   //Point courant :
746   Vxy.SetLinearForm (Xc*MajorRadius, Xdir, 
747                      Yc*MinorRadius, Ydir,
748                      Pos.Location().XY());
749   P.SetXY (Vxy);
750   
751   //V1 :
752   Vxy.SetLinearForm (Yc*MajorRadius, Xdir, Xc*MinorRadius, Ydir);
753   V1.SetXY (Vxy);
754 }
755
756 //=======================================================================
757 //function : ParabolaD1
758 //purpose  : 
759 //=======================================================================
760
761 void ElCLib::ParabolaD1 (const Standard_Real U,
762                          const gp_Ax22d& Pos,
763                          const Standard_Real Focal,
764                          gp_Pnt2d& P,
765                          gp_Vec2d& V1)
766 {
767   gp_XY Vxy;
768   gp_XY Xdir (Pos.XDirection().XY());
769   if (Focal == 0.0) {      //Parabole degenere en une droite
770     V1.SetXY (Xdir);
771     Vxy.SetLinearForm (U, Xdir, Pos.Location().XY());
772   }
773   else {
774     gp_XY Ydir (Pos.YDirection().XY());
775     Vxy.SetLinearForm (U / (2.0 * Focal), Xdir, Ydir);
776     V1.SetXY (Vxy);
777     Vxy.SetLinearForm ((U * U) / (4.0 * Focal), Xdir, 
778                        U, Ydir,
779                        Pos.Location().XY());
780   }
781   P.SetXY (Vxy);
782 }
783
784 //=======================================================================
785 //function : CircleD2
786 //purpose  : 
787 //=======================================================================
788
789 void ElCLib::CircleD2 (const Standard_Real U,
790                        const gp_Ax22d& Pos,
791                        const Standard_Real Radius, 
792                        gp_Pnt2d& P,
793                        gp_Vec2d& V1,
794                        gp_Vec2d& V2)
795 {
796   gp_XY Vxy;
797   gp_XY Xdir (Pos.XDirection().XY());
798   gp_XY Ydir (Pos.YDirection().XY());
799   Standard_Real Xc = Radius * cos(U);
800   Standard_Real Yc = Radius * sin(U);
801   //V2 :
802   Vxy.SetLinearForm (Xc, Xdir, Yc, Ydir);
803   V2.SetXY (Vxy);
804   V2.Reverse();
805   Vxy.Add (Pos.Location().XY());
806   P.SetXY (Vxy);
807
808   //V1 :
809   Vxy.SetLinearForm (-Yc, Xdir, Xc, Ydir);
810   V1.SetXY (Vxy);
811 }
812
813 //=======================================================================
814 //function : EllipseD2
815 //purpose  : 
816 //=======================================================================
817
818 void ElCLib::EllipseD2 (const Standard_Real U,
819                         const gp_Ax22d& Pos,
820                         const Standard_Real MajorRadius,
821                         const Standard_Real MinorRadius,
822                         gp_Pnt2d& P,
823                         gp_Vec2d& V1,
824                         gp_Vec2d& V2)
825 {
826   gp_XY Vxy;
827   gp_XY Xdir (Pos.XDirection().XY());
828   gp_XY Ydir (Pos.YDirection().XY());
829   Standard_Real Xc = cos(U);
830   Standard_Real Yc = sin(U);
831
832   //V2 :
833   Vxy.SetLinearForm (Xc*MajorRadius, Xdir, Yc*MinorRadius, Ydir);
834   V2.SetXY (Vxy);
835   V2.Reverse ();
836
837   //Point courant :
838   Vxy.Add (Pos.Location().XY());
839   P.SetXY (Vxy);
840
841   //V1 :
842   Vxy.SetLinearForm (-Yc*MajorRadius, Xdir, Xc*MinorRadius, Ydir);
843   V1.SetXY (Vxy);
844 }
845
846 //=======================================================================
847 //function : HyperbolaD2
848 //purpose  : 
849 //=======================================================================
850
851 void ElCLib::HyperbolaD2 (const Standard_Real U,
852                           const gp_Ax22d& Pos,
853                           const Standard_Real MajorRadius,
854                           const Standard_Real MinorRadius,
855                           gp_Pnt2d& P,
856                           gp_Vec2d& V1,
857                           gp_Vec2d& V2)
858 {
859   gp_XY Vxy;
860   gp_XY Xdir (Pos.XDirection().XY()); 
861   gp_XY Ydir (Pos.YDirection().XY()); 
862   Standard_Real Xc = Cosh(U);
863   Standard_Real Yc = Sinh(U);
864
865   //V2 :
866   Vxy.SetLinearForm (Xc*MajorRadius, Xdir, Yc*MinorRadius, Ydir);
867   V2.SetXY (Vxy);
868
869   //Point courant :
870   Vxy.Add (Pos.Location().XY());
871   P.SetXY (Vxy);
872
873   //V1 :
874   Vxy.SetLinearForm (Yc*MajorRadius, Xdir, Xc*MinorRadius, Ydir);
875   V1.SetXY (Vxy);
876 }
877
878 //=======================================================================
879 //function : ParabolaD2
880 //purpose  : 
881 //=======================================================================
882
883 void ElCLib::ParabolaD2 (const Standard_Real U,
884                          const gp_Ax22d& Pos,
885                          const Standard_Real Focal,
886                          gp_Pnt2d& P,
887                          gp_Vec2d& V1,
888                          gp_Vec2d& V2)
889 {
890   gp_XY Vxy;
891   gp_XY Xdir (Pos.XDirection().XY());
892   if (Focal == 0.0) {
893     V2.SetCoord (0.0, 0.0);
894     V1.SetXY (Xdir);
895     Vxy.SetLinearForm (U, Xdir, Pos.Location().XY());
896   }
897   else {
898     gp_XY Ydir (Pos.YDirection().XY());
899     Vxy = Xdir.Multiplied (1.0 / (2.0 * Focal));
900     V2.SetXY (Vxy);
901     Vxy.SetLinearForm (U, Vxy, Ydir);
902     V1.SetXY (Vxy);
903     Vxy.SetLinearForm (U * U / (4.0 * Focal), Xdir, U, Ydir);
904     Vxy.Add (Pos.Location().XY());
905   }
906   P.SetXY (Vxy);
907 }
908
909 //=======================================================================
910 //function : CircleD3
911 //purpose  : 
912 //=======================================================================
913
914 void ElCLib::CircleD3 (const Standard_Real U,
915                        const gp_Ax22d& Pos,
916                        const Standard_Real Radius,
917                        gp_Pnt2d& P,
918                        gp_Vec2d& V1,
919                        gp_Vec2d& V2,
920                        gp_Vec2d& V3)
921 {
922   gp_XY Vxy;
923   gp_XY Xdir (Pos.XDirection().XY());
924   gp_XY Ydir (Pos.YDirection().XY());
925   Standard_Real Xc = Radius * cos(U);
926   Standard_Real Yc = Radius * sin(U);
927
928   //V2 :
929   Vxy.SetLinearForm (Xc, Xdir, Yc, Ydir);
930   V2.SetXY (Vxy);
931   V2.Reverse();
932
933   //Point courant :
934   Vxy.Add (Pos.Location().XY());
935   P.SetXY (Vxy);
936
937   //V1 :
938   Vxy.SetLinearForm (-Yc, Xdir, Xc, Ydir);
939   V1.SetXY (Vxy);
940
941   //V3 :
942   V3.SetXY (Vxy);
943   V3.Reverse ();
944 }
945
946 //=======================================================================
947 //function : EllipseD3
948 //purpose  : 
949 //=======================================================================
950
951 void ElCLib::EllipseD3 (const Standard_Real U,
952                         const gp_Ax22d& Pos,
953                         const Standard_Real MajorRadius,
954                         const Standard_Real MinorRadius,
955                         gp_Pnt2d& P,
956                         gp_Vec2d& V1,
957                         gp_Vec2d& V2,
958                         gp_Vec2d& V3)
959 {
960   gp_XY Vxy;
961   gp_XY Xdir (Pos.XDirection().XY());
962   gp_XY Ydir (Pos.YDirection().XY());
963   Standard_Real Xc = cos(U);
964   Standard_Real Yc = sin(U);
965
966   //V2 :
967   Vxy.SetLinearForm (Xc*MajorRadius, Xdir, Yc*MinorRadius, Ydir);
968   V2.SetXY (Vxy);
969   V2.Reverse ();
970
971   //Point courant :
972   Vxy.Add (Pos.Location().XY());
973   P.SetXY (Vxy);
974
975   //V1 :
976   Vxy.SetLinearForm (-Yc*MajorRadius, Xdir, Xc*MinorRadius, Ydir);
977   V1.SetXY (Vxy);
978
979   //V3 :
980   V3.SetXY (Vxy);
981   V3.Reverse ();
982 }
983
984 //=======================================================================
985 //function : HyperbolaD3
986 //purpose  : 
987 //=======================================================================
988
989 void ElCLib::HyperbolaD3 (const Standard_Real U,
990                           const gp_Ax22d& Pos,
991                           const Standard_Real MajorRadius,
992                           const Standard_Real MinorRadius,
993                           gp_Pnt2d& P,
994                           gp_Vec2d& V1,
995                           gp_Vec2d& V2,
996                           gp_Vec2d& V3)
997 {
998   gp_XY Vxy;
999   gp_XY Xdir (Pos.XDirection().XY());
1000   gp_XY Ydir (Pos.YDirection().XY());
1001   Standard_Real Xc = Cosh(U);
1002   Standard_Real Yc = Sinh(U);
1003
1004   //V2 :
1005   Vxy.SetLinearForm (Xc*MajorRadius, Xdir, Yc*MinorRadius, Ydir);
1006   V2.SetXY (Vxy);
1007
1008   //Point courant :
1009   Vxy.Add (Pos.Location().XY());
1010   P.SetXY (Vxy);
1011
1012   //V1 :
1013   Vxy.SetLinearForm (Yc*MajorRadius, Xdir, Xc*MinorRadius, Ydir);
1014   V1.SetXY (Vxy);
1015
1016   //V3 :
1017   V3.SetXY (Vxy);
1018 }
1019
1020 //=======================================================================
1021 //function : LineDN
1022 //purpose  : 
1023 //=======================================================================
1024
1025 gp_Vec ElCLib::LineDN (const Standard_Real,
1026                        const gp_Ax1& Pos,
1027                        const Standard_Integer N) 
1028 {
1029   if (N == 1) { return gp_Vec(Pos.Direction()); }
1030   return gp_Vec (0., 0., 0.);
1031 }
1032
1033 //=======================================================================
1034 //function : CircleDN
1035 //purpose  : 
1036 //=======================================================================
1037
1038 gp_Vec ElCLib::CircleDN (const Standard_Real U,
1039                          const gp_Ax2& Pos,
1040                          const Standard_Real Radius,
1041                          const Standard_Integer N) 
1042 {
1043   Standard_Real Xc=0, Yc=0;
1044   if (N == 1) {       
1045     Xc = Radius * -sin(U);
1046     Yc = Radius *  cos(U);
1047   }
1048   else if ((N + 2) % 4 == 0) {
1049     Xc = Radius * -cos(U);
1050     Yc = Radius * -sin(U);
1051   }
1052   else if ((N + 1) % 4 == 0) {
1053     Xc = Radius *  sin(U);
1054     Yc = Radius * -cos(U);
1055   }
1056   else if (N % 4 == 0) {
1057     Xc = Radius *  cos(U);
1058     Yc = Radius *  sin(U);
1059   }
1060   else if ((N-1) % 4 == 0) {
1061     Xc = Radius * -sin(U);
1062     Yc = Radius *  cos(U);
1063   }
1064   gp_XYZ Coord1 (Pos.XDirection().XYZ());
1065   Coord1.SetLinearForm (Xc, Coord1, Yc, Pos.YDirection().XYZ());
1066   return gp_Vec (Coord1);
1067 }
1068
1069 //=======================================================================
1070 //function : EllipseDN
1071 //purpose  : 
1072 //=======================================================================
1073
1074 gp_Vec ElCLib::EllipseDN (const Standard_Real U,
1075                           const gp_Ax2& Pos,
1076                           const Standard_Real MajorRadius,
1077                           const Standard_Real MinorRadius,
1078                           const Standard_Integer N)
1079 {
1080   Standard_Real Xc=0, Yc=0;
1081   if (N == 1) {       
1082     Xc = MajorRadius * -sin(U);
1083     Yc = MinorRadius *  cos(U);
1084   }
1085   else if ((N + 2) % 4 == 0) {
1086     Xc = MajorRadius * -cos(U);
1087     Yc = MinorRadius * -sin(U);
1088   }
1089   else if ((N + 1) % 4 == 0) {
1090     Xc = MajorRadius *  sin(U);
1091     Yc = MinorRadius * -cos(U);
1092   }
1093   else if (N % 4 == 0) {
1094     Xc = MajorRadius *  cos(U);
1095     Yc = MinorRadius *  sin(U);
1096   }
1097   else if ((N-1) % 4 == 0) {
1098     Xc = MajorRadius * -sin(U);
1099     Yc = MinorRadius *  cos(U);
1100   }
1101   gp_XYZ Coord1 (Pos.XDirection().XYZ());
1102   Coord1.SetLinearForm (Xc, Coord1, Yc, Pos.YDirection().XYZ());
1103   return gp_Vec (Coord1);
1104 }
1105
1106 //=======================================================================
1107 //function : HyperbolaDN
1108 //purpose  : 
1109 //=======================================================================
1110
1111 gp_Vec ElCLib::HyperbolaDN (const Standard_Real U,
1112                             const gp_Ax2& Pos,
1113                             const Standard_Real MajorRadius,
1114                             const Standard_Real MinorRadius,
1115                             const Standard_Integer N)
1116 {
1117   Standard_Real Xc=0, Yc=0;
1118   if (IsOdd (N)) {       
1119     Xc = MajorRadius * Sinh(U);
1120     Yc = MinorRadius * Cosh(U);
1121   }
1122   else if (IsEven (N)) {
1123     Xc = MajorRadius * Cosh(U);
1124     Yc = MinorRadius * Sinh(U);
1125   }
1126   gp_XYZ Coord1 (Pos.XDirection().XYZ());
1127   Coord1.SetLinearForm (Xc, Coord1, Yc, Pos.YDirection().XYZ());
1128   return gp_Vec (Coord1);
1129 }
1130
1131 //=======================================================================
1132 //function : ParabolaDN
1133 //purpose  : 
1134 //=======================================================================
1135
1136 gp_Vec ElCLib::ParabolaDN (const Standard_Real U,
1137                            const gp_Ax2& Pos,
1138                            const Standard_Real Focal,
1139                            const Standard_Integer N) 
1140 {
1141   if (N <= 2) {
1142     gp_XYZ Coord1 (Pos.XDirection().XYZ());
1143     if (N == 1) {
1144       if (Focal == 0.0) { 
1145         return gp_Vec(Coord1);
1146       }
1147       else {
1148         Coord1.SetLinearForm
1149           (U / (2.0 * Focal), Coord1, Pos.YDirection().XYZ());
1150         return gp_Vec (Coord1);
1151       }
1152     }
1153     else if (N == 2) {
1154       if (Focal == 0.0) { 
1155         return gp_Vec(0.0, 0.0, 0.0);
1156       }
1157       else {
1158         Coord1.Multiply ( 1.0 / (2.0 * Focal));
1159         return gp_Vec (Coord1);
1160       }
1161     }
1162   }
1163   return gp_Vec (0.,0.,0.);
1164 }
1165
1166 //=======================================================================
1167 //function : LineDN
1168 //purpose  : 
1169 //=======================================================================
1170
1171 gp_Vec2d ElCLib::LineDN (const Standard_Real,
1172                          const gp_Ax2d& Pos,
1173                          const Standard_Integer N) 
1174 {
1175   if (N == 1) { return gp_Vec2d (Pos.Direction ()); }
1176   return gp_Vec2d (0.0, 0.0);
1177 }
1178
1179 //=======================================================================
1180 //function : CircleDN
1181 //purpose  : 
1182 //=======================================================================
1183
1184 gp_Vec2d ElCLib::CircleDN (const Standard_Real U,
1185                            const gp_Ax22d& Pos,
1186                            const Standard_Real Radius,
1187                            const Standard_Integer N)
1188 {
1189   Standard_Real Xc=0, Yc=0;
1190   if (N == 1) {       
1191     Xc = Radius * -sin(U);
1192     Yc = Radius *  cos(U);
1193   }
1194   else if ((N + 2) % 4 == 0) {
1195     Xc = Radius * -cos(U);
1196     Yc = Radius * -sin(U);
1197   }
1198   else if ((N + 1) % 4 == 0) {
1199     Xc = Radius *  sin(U);
1200     Yc = Radius * -cos(U);
1201   }
1202   else if (N % 4 == 0) {
1203     Xc = Radius *  cos(U);
1204     Yc = Radius *  sin(U);
1205   }
1206   else if ((N-1) % 4 == 0) {
1207     Xc = Radius * -sin(U);
1208     Yc = Radius *  cos(U);
1209   }
1210   gp_XY Xdir (Pos.XDirection().XY());
1211   gp_XY Ydir (Pos.YDirection().XY());
1212   Xdir.SetLinearForm (Xc, Xdir, Yc, Ydir);
1213   return gp_Vec2d (Xdir);
1214 }
1215
1216 //=======================================================================
1217 //function : EllipseDN
1218 //purpose  : 
1219 //=======================================================================
1220
1221 gp_Vec2d ElCLib::EllipseDN (const Standard_Real U,
1222                             const gp_Ax22d& Pos,
1223                             const Standard_Real MajorRadius,
1224                             const Standard_Real MinorRadius,
1225                             const Standard_Integer N)
1226 {
1227   Standard_Real Xc=0, Yc=0;
1228   if (N == 1) {       
1229     Xc = MajorRadius * -sin(U);
1230     Yc = MinorRadius *  cos(U);
1231   }
1232   else if ((N + 2) % 4 == 0) {
1233     Xc = MajorRadius * -cos(U);
1234     Yc = MinorRadius * -sin(U);
1235   }
1236   else if ((N + 1) % 4 == 0) {
1237     Xc = MajorRadius *  sin(U);
1238     Yc = MinorRadius * -cos(U);
1239   }
1240   else if (N % 4 == 0) {
1241     Xc = MajorRadius *  cos(U);
1242     Yc = MinorRadius *  sin(U);
1243   }
1244   else if ((N-1) % 4 == 0) {
1245     Xc = MajorRadius * -sin(U);
1246     Yc = MinorRadius *  cos(U);
1247   }
1248   gp_XY Xdir (Pos.XDirection().XY());
1249   gp_XY Ydir (Pos.YDirection().XY());
1250   Xdir.SetLinearForm (Xc, Xdir, Yc, Ydir);
1251   return gp_Vec2d (Xdir);
1252 }
1253
1254 //=======================================================================
1255 //function : HyperbolaDN
1256 //purpose  : 
1257 //=======================================================================
1258
1259 gp_Vec2d ElCLib::HyperbolaDN (const Standard_Real U,
1260                               const gp_Ax22d& Pos,
1261                               const Standard_Real MajorRadius,
1262                               const Standard_Real MinorRadius,
1263                               const Standard_Integer N)
1264 {
1265   Standard_Real Xc=0, Yc=0;
1266   if (IsOdd (N)) {       
1267     Xc = MajorRadius * Sinh(U);
1268     Yc = MinorRadius * Cosh(U);
1269   }
1270   else if (IsEven (N)) {
1271     Xc = MajorRadius * Cosh(U);
1272     Yc = MinorRadius * Sinh(U);
1273   }
1274   gp_XY Xdir (Pos.XDirection().XY());
1275   gp_XY Ydir (Pos.YDirection().XY());
1276   Xdir.SetLinearForm (Xc, Xdir, Yc, Ydir);
1277   return gp_Vec2d (Xdir);
1278 }
1279
1280 //=======================================================================
1281 //function : ParabolaDN
1282 //purpose  : 
1283 //=======================================================================
1284
1285 gp_Vec2d ElCLib::ParabolaDN (const Standard_Real U,
1286                              const gp_Ax22d& Pos,
1287                              const Standard_Real Focal,
1288                              const Standard_Integer N)
1289 {
1290   if (N <= 2)  {
1291     gp_XY Xdir (Pos.XDirection().XY());
1292     if (N == 1) {
1293       if (Focal == 0.0) { 
1294         return gp_Vec2d (Xdir);
1295       }
1296       else {
1297         gp_XY Ydir (Pos.YDirection().XY());
1298         Xdir.SetLinearForm (U / (2.0 * Focal), Xdir,  Ydir);
1299         return gp_Vec2d (Xdir);
1300       }
1301     }
1302     else if (N == 2) {
1303       if (Focal == 0.0) { 
1304         return gp_Vec2d (0.0, 0.0);
1305       }
1306       else {
1307         Xdir.Multiply ( 1.0 / (2.0 * Focal));
1308         return gp_Vec2d (Xdir);
1309       }
1310     }
1311   }
1312   return gp_Vec2d (0.0, 0.0); 
1313 }
1314
1315 //=======================================================================
1316 //function : LineParameter
1317 //purpose  : 
1318 //=======================================================================
1319
1320 Standard_Real ElCLib::LineParameter (const gp_Ax1& L, const gp_Pnt& P)
1321 {
1322   return (P.XYZ() - L.Location().XYZ()).Dot (L.Direction().XYZ());
1323 }
1324
1325 //=======================================================================
1326 //function : CircleParameter
1327 //purpose  : 
1328 //=======================================================================
1329 Standard_Real ElCLib::CircleParameter(const gp_Ax2& Pos,
1330                                       const gp_Pnt& P)
1331 {
1332   gp_Vec aVec(Pos.Location(), P);
1333   if (aVec.SquareMagnitude() < gp::Resolution())
1334     // coinciding points -> infinite number of parameters
1335     return 0.0;
1336
1337   const gp_Dir& dir = Pos.Direction();
1338   // Project vector on circle's plane
1339   gp_XYZ aVProj = dir.XYZ().CrossCrossed(aVec.XYZ(), dir.XYZ());
1340
1341   if (aVProj.SquareModulus() < gp::Resolution())
1342     return 0.0;
1343
1344   // Angle between X direction and projected vector
1345   Standard_Real Teta = (Pos.XDirection()).AngleWithRef(aVProj, dir);
1346
1347   if      (Teta < -1.e-16)  Teta += PIPI;
1348   else if (Teta < 0)        Teta = 0;
1349   return Teta;
1350 }
1351
1352 //=======================================================================
1353 //function : EllipseParameter
1354 //purpose  : 
1355 //=======================================================================
1356
1357 Standard_Real ElCLib::EllipseParameter (const gp_Ax2& Pos,
1358                                         const Standard_Real MajorRadius,
1359                                         const Standard_Real MinorRadius,
1360                                         const gp_Pnt& P)
1361 {
1362   gp_XYZ  OP = P.XYZ()-Pos.Location().XYZ();
1363   gp_XYZ xaxis = Pos.XDirection().XYZ();
1364   gp_XYZ yaxis = Pos.YDirection().XYZ();
1365   Standard_Real NY = OP.Dot(yaxis);
1366   Standard_Real NX = OP.Dot(xaxis); 
1367
1368   if(  (Abs(NX) <= gp::Resolution())
1369      &&(Abs(NY) <= gp::Resolution()))
1370     //-- The point P is on the Axis of the Ellipse. 
1371     return(0.0);
1372   
1373   yaxis.Multiply (NY * (MajorRadius/MinorRadius));
1374   gp_XYZ Om = xaxis.Multiplied (NX);
1375   Om.Add (yaxis); 
1376   Standard_Real Teta = gp_Vec(xaxis).AngleWithRef
1377     (gp_Vec(Om), gp_Vec(Pos.Direction()));
1378   if      (Teta < -1.e-16)  Teta += PIPI;
1379   else if (Teta < 0)        Teta = 0;
1380   return Teta;
1381 }
1382
1383 //=======================================================================
1384 //function : HyperbolaParameter
1385 //purpose  : 
1386 //=======================================================================
1387
1388 Standard_Real ElCLib::HyperbolaParameter (const gp_Ax2& Pos,
1389                                           const Standard_Real,
1390                                           const Standard_Real MinorRadius,
1391                                           const gp_Pnt& P)
1392 {
1393   Standard_Real sht = 
1394     gp_Vec(Pos.Location (), P).Dot
1395       (gp_Vec (Pos.YDirection())) / MinorRadius;
1396
1397 #if defined(__QNX__)
1398   return std::asinh(sht);
1399 #else
1400   return asinh(sht);
1401 #endif
1402 }
1403
1404 //=======================================================================
1405 //function : ParabolaParameter
1406 //purpose  : 
1407 //=======================================================================
1408
1409 Standard_Real ElCLib::ParabolaParameter (const gp_Ax2& Pos,
1410                                          const gp_Pnt& P)
1411 {
1412   return gp_Vec(Pos.Location(),P).Dot(gp_Vec(Pos.YDirection()));
1413 }
1414
1415 //=======================================================================
1416 //function : LineParameter
1417 //purpose  : 
1418 //=======================================================================
1419
1420 Standard_Real ElCLib::LineParameter (const gp_Ax2d& L,
1421                                      const gp_Pnt2d& P)
1422 {
1423   gp_XY Coord = P.XY();
1424   Coord.Subtract (L.Location().XY());
1425   return Coord.Dot (L.Direction().XY());
1426 }
1427
1428 //=======================================================================
1429 //function : CircleParameter
1430 //purpose  : 
1431 //=======================================================================
1432
1433 Standard_Real ElCLib::CircleParameter (const gp_Ax22d& Pos,
1434                                        const gp_Pnt2d& P)
1435 {
1436   Standard_Real Teta = (Pos.XDirection()).Angle
1437     (gp_Vec2d (Pos.Location(),P));
1438   Teta = ((Pos.XDirection() ^ Pos.YDirection()) >= 0.0) ? Teta: -Teta;
1439   if      (Teta < -1.e-16)  Teta += PIPI;
1440   else if (Teta < 0)        Teta = 0;
1441   return Teta;
1442 }
1443
1444 //=======================================================================
1445 //function : EllipseParameter
1446 //purpose  : 
1447 //=======================================================================
1448
1449 Standard_Real ElCLib::EllipseParameter (const gp_Ax22d& Pos,
1450                                         const Standard_Real MajorRadius,
1451                                         const Standard_Real MinorRadius, 
1452                                         const gp_Pnt2d& P)
1453 {
1454   gp_XY  OP = P.XY();
1455   OP.Subtract (Pos.Location().XY());
1456   gp_XY xaxis = Pos.XDirection().XY();
1457   gp_XY yaxis = Pos.YDirection().XY();
1458   gp_XY Om = xaxis.Multiplied (OP.Dot(xaxis));
1459   yaxis.Multiply ( (OP.Dot(yaxis)) * (MajorRadius/MinorRadius) );
1460   Om.Add (yaxis); 
1461   Standard_Real Teta = gp_Vec2d(xaxis).Angle (gp_Vec2d(Om));
1462   Teta = ((Pos.XDirection() ^ Pos.YDirection()) >= 0.0) ? Teta: -Teta;
1463   if      (Teta < -1.e-16)  Teta += PIPI;
1464   else if (Teta < 0)        Teta = 0;
1465   return Teta;
1466 }
1467
1468 //=======================================================================
1469 //function : HyperbolaParameter
1470 //purpose  : 
1471 //=======================================================================
1472
1473 Standard_Real ElCLib::HyperbolaParameter (const gp_Ax22d& Pos,
1474                                           const Standard_Real,
1475                                           const Standard_Real MinorRadius, 
1476                                           const gp_Pnt2d& P)
1477 {
1478   gp_Vec2d V (Pos.YDirection().XY());
1479   Standard_Real sht = gp_Vec2d(Pos.Location(),P).Dot(V) /MinorRadius;
1480 #if defined(__QNX__)
1481   return std::asinh(sht);
1482 #else
1483   return asinh(sht);
1484 #endif
1485 }
1486
1487 //=======================================================================
1488 //function : ParabolaParameter
1489 //purpose  : 
1490 //=======================================================================
1491
1492 Standard_Real ElCLib::ParabolaParameter (const gp_Ax22d& Pos,
1493                                          const gp_Pnt2d& P)
1494 {
1495   gp_Vec2d Directrix (Pos.YDirection().XY());
1496   return gp_Vec2d(Pos.Location(),P).Dot(Directrix);
1497 }
1498
1499 //=======================================================================
1500 //function : To3d
1501 //purpose  : 
1502 //=======================================================================
1503
1504 gp_Pnt ElCLib::To3d (const gp_Ax2& Pos, const gp_Pnt2d& P)
1505 {
1506   gp_XYZ Vxy = Pos.XDirection().XYZ();
1507   Vxy.SetLinearForm (P.X(), Vxy, P.Y(), Pos.YDirection().XYZ(), 
1508                      Pos.Location().XYZ());
1509   return gp_Pnt (Vxy);
1510
1511 }
1512
1513 //=======================================================================
1514 //function : To3d
1515 //purpose  : 
1516 //=======================================================================
1517
1518 gp_Dir ElCLib::To3d (const gp_Ax2& Pos, const gp_Dir2d& V)
1519 {
1520   gp_Vec Vx = Pos.XDirection();
1521   gp_Vec Vy = Pos.YDirection();
1522   Vx.Multiply (V.X());
1523   Vy.Multiply (V.Y());
1524   Vx.Add(Vy);
1525   return gp_Dir (Vx);
1526 }
1527
1528 //=======================================================================
1529 //function : To3d
1530 //purpose  : 
1531 //=======================================================================
1532
1533 gp_Vec ElCLib::To3d (const gp_Ax2& Pos, const gp_Vec2d& V)
1534 {
1535   gp_Vec Vx = Pos.XDirection();
1536   gp_Vec Vy = Pos.YDirection();
1537   Vx.Multiply (V.X());
1538   Vy.Multiply (V.Y());
1539   Vx.Add(Vy);
1540   return Vx;
1541 }
1542
1543 //=======================================================================
1544 //function : To3d
1545 //purpose  : 
1546 //=======================================================================
1547
1548 gp_Ax1 ElCLib::To3d (const gp_Ax2& Pos, const gp_Ax2d& A)
1549 {
1550   gp_Pnt P  = ElCLib::To3d (Pos, A.Location());
1551   gp_Vec V  = ElCLib::To3d (Pos, A.Direction());
1552   return gp_Ax1 (P, V);
1553 }
1554
1555 //=======================================================================
1556 //function : To3d
1557 //purpose  : 
1558 //=======================================================================
1559
1560 gp_Ax2 ElCLib::To3d (const gp_Ax2& Pos, const gp_Ax22d& A)
1561 {
1562   gp_Pnt P  = ElCLib::To3d (Pos, A.Location());
1563   gp_Vec VX = ElCLib::To3d (Pos, A.XDirection());
1564   gp_Vec VY = ElCLib::To3d (Pos, A.YDirection());
1565   return gp_Ax2 (P, VX.Crossed(VY), VX);
1566 }
1567
1568 //=======================================================================
1569 //function : To3d
1570 //purpose  : 
1571 //=======================================================================
1572
1573 gp_Lin ElCLib::To3d (const gp_Ax2& Pos, const gp_Lin2d& L)
1574 {
1575   return gp_Lin (ElCLib::To3d (Pos, L.Position()));
1576 }
1577
1578 //=======================================================================
1579 //function : To3d
1580 //purpose  : 
1581 //=======================================================================
1582
1583 gp_Circ ElCLib::To3d (const gp_Ax2& Pos, const gp_Circ2d& C)
1584 {
1585   return gp_Circ (ElCLib::To3d (Pos, C.Axis()), C.Radius());
1586 }
1587
1588 //=======================================================================
1589 //function : To3d
1590 //purpose  : 
1591 //=======================================================================
1592
1593 gp_Elips ElCLib::To3d (const gp_Ax2& Pos, const gp_Elips2d& E)
1594 {
1595   return gp_Elips (ElCLib::To3d (Pos, E.Axis ()), E.MajorRadius (),
1596                    E.MinorRadius ());
1597 }
1598
1599 //=======================================================================
1600 //function : To3d
1601 //purpose  : 
1602 //=======================================================================
1603
1604 gp_Hypr ElCLib::To3d (const gp_Ax2& Pos, const gp_Hypr2d& H)
1605 {
1606   return gp_Hypr (ElCLib::To3d (Pos, H.Axis ()), H.MajorRadius (),
1607                   H.MinorRadius ());
1608 }
1609
1610 //=======================================================================
1611 //function : To3d
1612 //purpose  : 
1613 //=======================================================================
1614
1615 gp_Parab ElCLib::To3d (const gp_Ax2& Pos, const gp_Parab2d& Prb)
1616 {
1617   return gp_Parab ( ElCLib::To3d (Pos, Prb.Axis ()), Prb.Focal ());
1618 }
1619