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