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