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