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 |
47 | static 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 |
69 | Standard_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 | |
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 | 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 | |
111 | gp_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 | |
126 | gp_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 | |
145 | gp_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 | |
165 | gp_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 | |
185 | gp_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 | |
210 | void 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 | |
226 | void 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 | |
250 | void 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 | |
277 | void 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 | |
304 | void 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 | |
334 | void 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 | |
362 | void 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 | |
393 | void 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 | |
422 | void 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 | |
457 | void 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 | |
489 | void 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 | |
524 | void 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 | |
554 | gp_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 | |
568 | gp_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 | |
586 | gp_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 | |
605 | gp_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 | |
624 | gp_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 | |
647 | void 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 | |
663 | void 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 | |
687 | void 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 | |
715 | void 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 | |
743 | void 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 | |
771 | void 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 | |
800 | void 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 | |
833 | void 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 | |
865 | void 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 | |
896 | void 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 | |
933 | void 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 | |
971 | void 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 | |
1007 | gp_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 | |
1020 | gp_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 | |
1056 | gp_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 | |
1093 | gp_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 | |
1118 | gp_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 | |
1153 | gp_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 | |
1166 | gp_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 | |
1203 | gp_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 | |
1241 | gp_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 | |
1267 | gp_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 | |
1302 | Standard_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 | |
1312 | Standard_Real ElCLib::CircleParameter (const gp_Ax2& Pos, |
1313 | const gp_Pnt& P) |
1314 | { |
c5b89fa3 |
1315 | gp_Vec aVec(Pos.Location(), P); |
1316 | Standard_Real Teta = 0.0; |
1317 | if (aVec.SquareMagnitude() > gp::Resolution()) |
1318 | Teta = (Pos.XDirection()).AngleWithRef(aVec, Pos.Direction()); |
7fd59977 |
1319 | if (Teta < -1.e-16) Teta += PIPI; |
1320 | else if (Teta < 0) Teta = 0; |
1321 | return Teta; |
1322 | } |
1323 | |
1324 | //======================================================================= |
1325 | //function : EllipseParameter |
1326 | //purpose : |
1327 | //======================================================================= |
1328 | |
1329 | Standard_Real ElCLib::EllipseParameter (const gp_Ax2& Pos, |
1330 | const Standard_Real MajorRadius, |
1331 | const Standard_Real MinorRadius, |
1332 | const gp_Pnt& P) |
1333 | { |
1334 | gp_XYZ OP = P.XYZ()-Pos.Location().XYZ(); |
1335 | gp_XYZ xaxis = Pos.XDirection().XYZ(); |
1336 | gp_XYZ yaxis = Pos.YDirection().XYZ(); |
1337 | Standard_Real NY = OP.Dot(yaxis); |
1338 | Standard_Real NX = OP.Dot(xaxis); |
1339 | |
1340 | if( (Abs(NX) <= gp::Resolution()) |
1341 | &&(Abs(NY) <= gp::Resolution())) |
1342 | //-- The point P is on the Axis of the Ellipse. |
1343 | return(0.0); |
1344 | |
1345 | yaxis.Multiply (NY * (MajorRadius/MinorRadius)); |
1346 | gp_XYZ Om = xaxis.Multiplied (NX); |
1347 | Om.Add (yaxis); |
1348 | Standard_Real Teta = gp_Vec(xaxis).AngleWithRef |
1349 | (gp_Vec(Om), gp_Vec(Pos.Direction())); |
1350 | if (Teta < -1.e-16) Teta += PIPI; |
1351 | else if (Teta < 0) Teta = 0; |
1352 | return Teta; |
1353 | } |
1354 | |
1355 | //======================================================================= |
1356 | //function : HyperbolaParameter |
1357 | //purpose : |
1358 | //======================================================================= |
1359 | |
1360 | Standard_Real ElCLib::HyperbolaParameter (const gp_Ax2& Pos, |
1361 | const Standard_Real, |
1362 | const Standard_Real MinorRadius, |
1363 | const gp_Pnt& P) |
1364 | { |
1365 | Standard_Real sht = |
1366 | gp_Vec(Pos.Location (), P).Dot |
1367 | (gp_Vec (Pos.YDirection())) / MinorRadius; |
d8d01f6e |
1368 | |
ad779564 |
1369 | #if __QNX__ |
d8d01f6e |
1370 | return std::asinh(sht); |
1371 | #else |
7fd59977 |
1372 | return asinh(sht); |
d8d01f6e |
1373 | #endif |
7fd59977 |
1374 | } |
1375 | |
1376 | //======================================================================= |
1377 | //function : ParabolaParameter |
1378 | //purpose : |
1379 | //======================================================================= |
1380 | |
1381 | Standard_Real ElCLib::ParabolaParameter (const gp_Ax2& Pos, |
1382 | const gp_Pnt& P) |
1383 | { |
1384 | return gp_Vec(Pos.Location(),P).Dot(gp_Vec(Pos.YDirection())); |
1385 | } |
1386 | |
1387 | //======================================================================= |
1388 | //function : LineParameter |
1389 | //purpose : |
1390 | //======================================================================= |
1391 | |
1392 | Standard_Real ElCLib::LineParameter (const gp_Ax2d& L, |
1393 | const gp_Pnt2d& P) |
1394 | { |
1395 | gp_XY Coord = P.XY(); |
1396 | Coord.Subtract (L.Location().XY()); |
1397 | return Coord.Dot (L.Direction().XY()); |
1398 | } |
1399 | |
1400 | //======================================================================= |
1401 | //function : CircleParameter |
1402 | //purpose : |
1403 | //======================================================================= |
1404 | |
1405 | Standard_Real ElCLib::CircleParameter (const gp_Ax22d& Pos, |
1406 | const gp_Pnt2d& P) |
1407 | { |
1408 | Standard_Real Teta = (Pos.XDirection()).Angle |
1409 | (gp_Vec2d (Pos.Location(),P)); |
1410 | Teta = ((Pos.XDirection() ^ Pos.YDirection()) >= 0.0) ? Teta: -Teta; |
1411 | if (Teta < -1.e-16) Teta += PIPI; |
1412 | else if (Teta < 0) Teta = 0; |
1413 | return Teta; |
1414 | } |
1415 | |
1416 | //======================================================================= |
1417 | //function : EllipseParameter |
1418 | //purpose : |
1419 | //======================================================================= |
1420 | |
1421 | Standard_Real ElCLib::EllipseParameter (const gp_Ax22d& Pos, |
1422 | const Standard_Real MajorRadius, |
1423 | const Standard_Real MinorRadius, |
1424 | const gp_Pnt2d& P) |
1425 | { |
1426 | gp_XY OP = P.XY(); |
1427 | OP.Subtract (Pos.Location().XY()); |
1428 | gp_XY xaxis = Pos.XDirection().XY(); |
1429 | gp_XY yaxis = Pos.YDirection().XY(); |
1430 | gp_XY Om = xaxis.Multiplied (OP.Dot(xaxis)); |
1431 | yaxis.Multiply ( (OP.Dot(yaxis)) * (MajorRadius/MinorRadius) ); |
1432 | Om.Add (yaxis); |
1433 | Standard_Real Teta = gp_Vec2d(xaxis).Angle (gp_Vec2d(Om)); |
1434 | Teta = ((Pos.XDirection() ^ Pos.YDirection()) >= 0.0) ? Teta: -Teta; |
1435 | if (Teta < -1.e-16) Teta += PIPI; |
1436 | else if (Teta < 0) Teta = 0; |
1437 | return Teta; |
1438 | } |
1439 | |
1440 | //======================================================================= |
1441 | //function : HyperbolaParameter |
1442 | //purpose : |
1443 | //======================================================================= |
1444 | |
1445 | Standard_Real ElCLib::HyperbolaParameter (const gp_Ax22d& Pos, |
1446 | const Standard_Real, |
1447 | const Standard_Real MinorRadius, |
1448 | const gp_Pnt2d& P) |
1449 | { |
1450 | gp_Vec2d V (Pos.YDirection().XY()); |
1451 | Standard_Real sht = gp_Vec2d(Pos.Location(),P).Dot(V) /MinorRadius; |
ad779564 |
1452 | #if __QNX__ |
d8d01f6e |
1453 | return std::asinh(sht); |
1454 | #else |
1455 | return asinh(sht); |
1456 | #endif |
7fd59977 |
1457 | } |
1458 | |
1459 | //======================================================================= |
1460 | //function : ParabolaParameter |
1461 | //purpose : |
1462 | //======================================================================= |
1463 | |
1464 | Standard_Real ElCLib::ParabolaParameter (const gp_Ax22d& Pos, |
1465 | const gp_Pnt2d& P) |
1466 | { |
1467 | gp_Vec2d Directrix (Pos.YDirection().XY()); |
1468 | return gp_Vec2d(Pos.Location(),P).Dot(Directrix); |
1469 | } |
1470 | |
1471 | //======================================================================= |
1472 | //function : To3d |
1473 | //purpose : |
1474 | //======================================================================= |
1475 | |
1476 | gp_Pnt ElCLib::To3d (const gp_Ax2& Pos, const gp_Pnt2d& P) |
1477 | { |
1478 | gp_XYZ Vxy = Pos.XDirection().XYZ(); |
1479 | Vxy.SetLinearForm (P.X(), Vxy, P.Y(), Pos.YDirection().XYZ(), |
1480 | Pos.Location().XYZ()); |
1481 | return gp_Pnt (Vxy); |
1482 | |
1483 | } |
1484 | |
1485 | //======================================================================= |
1486 | //function : To3d |
1487 | //purpose : |
1488 | //======================================================================= |
1489 | |
1490 | gp_Dir ElCLib::To3d (const gp_Ax2& Pos, const gp_Dir2d& V) |
1491 | { |
1492 | gp_Vec Vx = Pos.XDirection(); |
1493 | gp_Vec Vy = Pos.YDirection(); |
1494 | Vx.Multiply (V.X()); |
1495 | Vy.Multiply (V.Y()); |
1496 | Vx.Add(Vy); |
1497 | return gp_Dir (Vx); |
1498 | } |
1499 | |
1500 | //======================================================================= |
1501 | //function : To3d |
1502 | //purpose : |
1503 | //======================================================================= |
1504 | |
1505 | gp_Vec ElCLib::To3d (const gp_Ax2& Pos, const gp_Vec2d& V) |
1506 | { |
1507 | gp_Vec Vx = Pos.XDirection(); |
1508 | gp_Vec Vy = Pos.YDirection(); |
1509 | Vx.Multiply (V.X()); |
1510 | Vy.Multiply (V.Y()); |
1511 | Vx.Add(Vy); |
1512 | return Vx; |
1513 | } |
1514 | |
1515 | //======================================================================= |
1516 | //function : To3d |
1517 | //purpose : |
1518 | //======================================================================= |
1519 | |
1520 | gp_Ax1 ElCLib::To3d (const gp_Ax2& Pos, const gp_Ax2d& A) |
1521 | { |
1522 | gp_Pnt P = ElCLib::To3d (Pos, A.Location()); |
1523 | gp_Vec V = ElCLib::To3d (Pos, A.Direction()); |
1524 | return gp_Ax1 (P, V); |
1525 | } |
1526 | |
1527 | //======================================================================= |
1528 | //function : To3d |
1529 | //purpose : |
1530 | //======================================================================= |
1531 | |
1532 | gp_Ax2 ElCLib::To3d (const gp_Ax2& Pos, const gp_Ax22d& A) |
1533 | { |
1534 | gp_Pnt P = ElCLib::To3d (Pos, A.Location()); |
1535 | gp_Vec VX = ElCLib::To3d (Pos, A.XDirection()); |
1536 | gp_Vec VY = ElCLib::To3d (Pos, A.YDirection()); |
1537 | return gp_Ax2 (P, VX.Crossed(VY), VX); |
1538 | } |
1539 | |
1540 | //======================================================================= |
1541 | //function : To3d |
1542 | //purpose : |
1543 | //======================================================================= |
1544 | |
1545 | gp_Lin ElCLib::To3d (const gp_Ax2& Pos, const gp_Lin2d& L) |
1546 | { |
1547 | return gp_Lin (ElCLib::To3d (Pos, L.Position())); |
1548 | } |
1549 | |
1550 | //======================================================================= |
1551 | //function : To3d |
1552 | //purpose : |
1553 | //======================================================================= |
1554 | |
1555 | gp_Circ ElCLib::To3d (const gp_Ax2& Pos, const gp_Circ2d& C) |
1556 | { |
1557 | return gp_Circ (ElCLib::To3d (Pos, C.Axis()), C.Radius()); |
1558 | } |
1559 | |
1560 | //======================================================================= |
1561 | //function : To3d |
1562 | //purpose : |
1563 | //======================================================================= |
1564 | |
1565 | gp_Elips ElCLib::To3d (const gp_Ax2& Pos, const gp_Elips2d& E) |
1566 | { |
1567 | return gp_Elips (ElCLib::To3d (Pos, E.Axis ()), E.MajorRadius (), |
1568 | E.MinorRadius ()); |
1569 | } |
1570 | |
1571 | //======================================================================= |
1572 | //function : To3d |
1573 | //purpose : |
1574 | //======================================================================= |
1575 | |
1576 | gp_Hypr ElCLib::To3d (const gp_Ax2& Pos, const gp_Hypr2d& H) |
1577 | { |
1578 | return gp_Hypr (ElCLib::To3d (Pos, H.Axis ()), H.MajorRadius (), |
1579 | H.MinorRadius ()); |
1580 | } |
1581 | |
1582 | //======================================================================= |
1583 | //function : To3d |
1584 | //purpose : |
1585 | //======================================================================= |
1586 | |
1587 | gp_Parab ElCLib::To3d (const gp_Ax2& Pos, const gp_Parab2d& Prb) |
1588 | { |
1589 | return gp_Parab ( ElCLib::To3d (Pos, Prb.Axis ()), Prb.Focal ()); |
1590 | } |
1591 | |