0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / ElSLib / ElSLib.cxx
CommitLineData
b311480e 1// Created on: 1991-09-09
2// Created by: Michel Chauvat
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17// Modified by skv - Tue Sep 9 15:10:35 2003 OCC620
18
19
20#ifndef No_Exception
21#define No_Exception
22#endif
23
42cf5bc1 24
25#include <ElSLib.hxx>
7fd59977 26#include <gp.hxx>
42cf5bc1 27#include <gp_Ax3.hxx>
28#include <gp_Circ.hxx>
42cf5bc1 29#include <gp_Lin.hxx>
42cf5bc1 30#include <gp_Pnt.hxx>
7fd59977 31#include <gp_Trsf.hxx>
42cf5bc1 32#include <gp_Vec.hxx>
33#include <gp_XYZ.hxx>
7fd59977 34
c6541a0c 35static Standard_Real PIPI = M_PI + M_PI;
7fd59977 36
37gp_Pnt ElSLib::PlaneValue (const Standard_Real U,
38 const Standard_Real V,
39 const gp_Ax3& Pos)
40{
41 const gp_XYZ& XDir = Pos.XDirection().XYZ();
42 const gp_XYZ& YDir = Pos.YDirection().XYZ();
43 const gp_XYZ& PLoc = Pos.Location ().XYZ();
44 return gp_Pnt(U * XDir.X() + V * YDir.X() + PLoc.X(),
45 U * XDir.Y() + V * YDir.Y() + PLoc.Y(),
46 U * XDir.Z() + V * YDir.Z() + PLoc.Z());
47}
48
49gp_Pnt ElSLib::ConeValue (const Standard_Real U,
50 const Standard_Real V,
51 const gp_Ax3& Pos,
52 const Standard_Real Radius,
53 const Standard_Real SAngle)
54{
55 const gp_XYZ& XDir = Pos.XDirection().XYZ();
56 const gp_XYZ& YDir = Pos.YDirection().XYZ();
57 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
58 const gp_XYZ& PLoc = Pos.Location ().XYZ();
59 Standard_Real R = Radius + V * sin(SAngle);
60 Standard_Real A3 = V * cos(SAngle);
61 Standard_Real A1 = R * cos(U);
62 Standard_Real A2 = R * sin(U);
63 return gp_Pnt(A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X() + PLoc.X(),
64 A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y() + PLoc.Y(),
65 A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z() + PLoc.Z());
66}
67
68gp_Pnt ElSLib::CylinderValue (const Standard_Real U,
69 const Standard_Real V,
70 const gp_Ax3& Pos,
71 const Standard_Real Radius)
72{
73 // M(u,v) = C + Radius * ( Xdir * Cos(u) + Ydir * Sin(u)) + V * Zdir
74 // where C is the location point of the Axis2placement
75 // Xdir, Ydir ,Zdir are the directions of the local coordinates system
76
77 const gp_XYZ& XDir = Pos.XDirection().XYZ();
78 const gp_XYZ& YDir = Pos.YDirection().XYZ();
79 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
80 const gp_XYZ& PLoc = Pos.Location ().XYZ();
81 Standard_Real A1 = Radius * cos(U);
82 Standard_Real A2 = Radius * sin(U);
83 return gp_Pnt(A1 * XDir.X() + A2 * YDir.X() + V * ZDir.X() + PLoc.X(),
84 A1 * XDir.Y() + A2 * YDir.Y() + V * ZDir.Y() + PLoc.Y(),
85 A1 * XDir.Z() + A2 * YDir.Z() + V * ZDir.Z() + PLoc.Z());
86}
87
88gp_Pnt ElSLib::SphereValue (const Standard_Real U,
89 const Standard_Real V,
90 const gp_Ax3& Pos,
91 const Standard_Real Radius)
92{
93 //M(U,V) = Location +
94 // R * CosV (CosU * XDirection + SinU * YDirection) +
95 // R * SinV * Direction
96
97 const gp_XYZ& XDir = Pos.XDirection().XYZ();
98 const gp_XYZ& YDir = Pos.YDirection().XYZ();
99 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
100 const gp_XYZ& PLoc = Pos.Location ().XYZ();
101 Standard_Real R = Radius * cos(V);
102 Standard_Real A3 = Radius * sin(V);
103 Standard_Real A1 = R * cos(U);
104 Standard_Real A2 = R * sin(U);
105 return gp_Pnt(A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X() + PLoc.X(),
106 A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y() + PLoc.Y(),
107 A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z() + PLoc.Z());
108}
109
110gp_Pnt ElSLib::TorusValue (const Standard_Real U,
111 const Standard_Real V,
112 const gp_Ax3& Pos,
113 const Standard_Real MajorRadius,
114 const Standard_Real MinorRadius)
115{
116 //M(U,V) =
117 // Location +
118 // (MajRadius+MinRadius*Cos(V)) * (Cos(U)*XDirection + Sin(U)*YDirection) +
119 // MinorRadius * Sin(V) * Direction
120
121 const gp_XYZ& XDir = Pos.XDirection().XYZ();
122 const gp_XYZ& YDir = Pos.YDirection().XYZ();
123 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
124 const gp_XYZ& PLoc = Pos.Location ().XYZ();
125 Standard_Real R = MajorRadius + MinorRadius * cos(V);
126 Standard_Real A3 = MinorRadius * sin(V);
127 Standard_Real A1 = R * cos(U);
128 Standard_Real A2 = R * sin(U);
129 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
130 Standard_Real eps = 10.*(MinorRadius + MajorRadius)*RealEpsilon();
131
132 if (Abs(A1) <= eps)
133 A1 = 0.;
134
135 if (Abs(A2) <= eps)
136 A2 = 0.;
137
138 if (Abs(A3) <= eps)
139 A3 = 0.;
140
141 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
142 return gp_Pnt(A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X() + PLoc.X(),
143 A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y() + PLoc.Y(),
144 A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z() + PLoc.Z());
145}
146
147gp_Vec ElSLib::PlaneDN (const Standard_Real,
148 const Standard_Real,
149 const gp_Ax3& Pos,
150 const Standard_Integer Nu,
151 const Standard_Integer Nv)
152{
153 if (Nu == 0 && Nv == 1) { return gp_Vec (Pos.YDirection()); }
154 else if (Nu == 1 && Nv == 0) { return gp_Vec (Pos.XDirection()); }
155 return gp_Vec (0., 0., 0.);
156}
157
158gp_Vec ElSLib::ConeDN (const Standard_Real U,
159 const Standard_Real V,
160 const gp_Ax3& Pos,
161 const Standard_Real Radius,
162 const Standard_Real SAngle,
163 const Standard_Integer Nu,
164 const Standard_Integer Nv)
165{
166 gp_XYZ Xdir = Pos.XDirection().XYZ();
167 gp_XYZ Ydir = Pos.YDirection().XYZ();
c6541a0c 168 Standard_Real Um = U + Nu * M_PI_2; // M_PI * 0.5
7fd59977 169 Xdir.Multiply(cos(Um));
170 Ydir.Multiply(sin(Um));
171 Xdir.Add(Ydir);
172 if(Nv == 0) {
173 Xdir.Multiply(Radius + V * sin(SAngle));
174 if(Nu == 0) Xdir.Add(Pos.Location().XYZ());
175 return gp_Vec(Xdir);
176 }
177 else if(Nv == 1) {
178 Xdir.Multiply(sin(SAngle));
e4753a7d 179 if (Nu == 0)
180 Xdir.Add(Pos.Direction().XYZ() * cos(SAngle));
7fd59977 181 return gp_Vec(Xdir);
182 }
183 return gp_Vec(0.0,0.0,0.0);
184}
185
186gp_Vec ElSLib::CylinderDN (const Standard_Real U,
187 const Standard_Real,
188 const gp_Ax3& Pos,
189 const Standard_Real Radius,
190 const Standard_Integer Nu,
191 const Standard_Integer Nv)
192{
193 if (Nu + Nv < 1 || Nu < 0 || Nv < 0) { return gp_Vec(); }
194 if (Nv == 0) {
195 Standard_Real RCosU = Radius * cos(U);
196 Standard_Real RSinU = Radius * sin(U);
197 gp_XYZ Xdir = Pos.XDirection().XYZ();
198 gp_XYZ Ydir = Pos.YDirection().XYZ();
199 if ((Nu + 6) % 4 == 0) {
200 Xdir.Multiply (-RCosU);
201 Ydir.Multiply (-RSinU);
202 }
203 else if ((Nu + 5) % 4 == 0) {
204 Xdir.Multiply ( RSinU);
205 Ydir.Multiply (-RCosU);
206 }
207 else if ((Nu + 3) % 4 == 0) {
208 Xdir.Multiply (-RSinU);
209 Ydir.Multiply ( RCosU);
210 }
211 else if (Nu % 4 == 0) {
212 Xdir.Multiply ( RCosU);
213 Ydir.Multiply ( RSinU);
214 }
215 Xdir.Add (Ydir);
216 return gp_Vec (Xdir);
217 }
218 else if (Nv == 1 && Nu == 0) { return gp_Vec (Pos.Direction()); }
219 else { return gp_Vec (0.0, 0.0, 0.0); }
220}
221
222gp_Vec ElSLib::SphereDN (const Standard_Real U,
223 const Standard_Real V,
224 const gp_Ax3& Pos,
225 const Standard_Real Radius,
226 const Standard_Integer Nu,
227 const Standard_Integer Nv)
228{
229 if (Nu + Nv < 1 || Nu < 0 || Nv < 0) { return gp_Vec(); }
230 Standard_Real CosU = cos(U);
231 Standard_Real SinU = sin(U);
232 Standard_Real RCosV = Radius * cos(V);
233 const gp_XYZ& XDir = Pos.XDirection().XYZ();
234 const gp_XYZ& YDir = Pos.YDirection().XYZ();
235 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
236 Standard_Real A1,A2,A3,X,Y,Z;
237 if (Nu == 0) {
238 Standard_Real RSinV = Radius * sin(V);
239 if (IsOdd (Nv)) { A1 = - RSinV * CosU; A2 = - RSinV * SinU; A3 = RCosV; }
240 else { A1 = - RCosV * CosU; A2 = - RCosV * SinU; A3 = - RSinV; }
241 X = A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X();
242 Y = A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y();
243 Z = A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z();
244 if (!( (Nv + 2) % 4 == 0 || (Nv + 3) % 4 == 0 ))
245 { X = - X; Y = - Y; Z = - Z; }
246 }
247 else if (Nv == 0) {
248 if (IsOdd (Nu)) { A1 = - RCosV * SinU; A2 = RCosV * CosU; }
249 else { A1 = RCosV * CosU; A2 = RCosV * SinU; }
250 X = A1 * XDir.X() + A2 * YDir.X();
251 Y = A1 * XDir.Y() + A2 * YDir.Y();
252 Z = A1 * XDir.Z() + A2 * YDir.Z();
253 if ( (Nu + 2) % 4 == 0 || (Nu + 1) % 4 == 0 )
254 { X = - X; Y = - Y; Z = - Z; }
255 }
256 else {
257 Standard_Real RSinV = Radius * sin(V);
258 if (IsOdd (Nu)) { A1 = - SinU; A2 = CosU; }
259 else { A1 = - CosU; A2 = - SinU; }
260 if (IsOdd (Nv)) A3 = - RSinV;
261 else A3 = - RCosV;
262 X = (A1 * XDir.X() + A2 * YDir.X()) * A3;
263 Y = (A1 * XDir.Y() + A2 * YDir.Y()) * A3;
264 Z = (A1 * XDir.Z() + A2 * YDir.Z()) * A3;
265 if ((!((Nu + 2) % 4 == 0 || (Nu + 3) % 4 == 0) &&
266 ((Nv + 2) % 4 == 0 || (Nv + 3) % 4 == 0)) ||
267 (((Nu + 2) % 4 == 0 || (Nu + 3) % 4 == 0) &&
268 !((Nv + 2) % 4 == 0 || (Nv + 3) % 4 == 0)))
269 { X = - X; Y = - Y; Z = - Z; }
270 }
271 return gp_Vec(X,Y,Z);
272}
273
274gp_Vec ElSLib::TorusDN (const Standard_Real U,
275 const Standard_Real V,
276 const gp_Ax3& Pos,
277 const Standard_Real MajorRadius,
278 const Standard_Real MinorRadius,
279 const Standard_Integer Nu,
280 const Standard_Integer Nv)
281{
282 if (Nu + Nv < 1 || Nu < 0 || Nv < 0) { return gp_Vec(); }
283 Standard_Real CosU = cos(U);
284 Standard_Real SinU = sin(U);
285 const gp_XYZ& XDir = Pos.XDirection().XYZ();
286 const gp_XYZ& YDir = Pos.YDirection().XYZ();
287 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
288 Standard_Real A1,A2,A3,X=0,Y=0,Z=0;
289 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
290 Standard_Real eps = 10.*(MinorRadius + MajorRadius)*RealEpsilon();
291 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 End
292 if (Nv == 0) {
293 Standard_Real R = MajorRadius + MinorRadius * cos(V);
294 if (IsOdd (Nu)) { A1 = - R * SinU; A2 = R * CosU; }
295 else { A1 = - R * CosU; A2 = - R * SinU; }
296 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
297 if (Abs(A1) <= eps)
298 A1 = 0.;
299
300 if (Abs(A2) <= eps)
301 A2 = 0.;
302 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
303 X = A1 * XDir.X() + A2 * YDir.X();
304 Y = A1 * XDir.Y() + A2 * YDir.Y();
305 Z = A1 * XDir.Z() + A2 * YDir.Z();
306 if (!((Nu + 2) % 4 == 0 || (Nu + 3) % 4 == 0))
307 { X = - X; Y = - Y; Z = - Z; }
308 }
309 else if (Nu == 0) {
310 Standard_Real RCosV = MinorRadius * cos(V);
311 Standard_Real RSinV = MinorRadius * sin(V);
312 if (IsOdd (Nv)) { A1 = - RSinV * CosU; A2 = - RSinV * SinU; A3 = RCosV; }
313 else { A1 = - RCosV * CosU; A2 = - RCosV * SinU; A3 = - RSinV; }
314 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
315 if (Abs(A1) <= eps)
316 A1 = 0.;
317
318 if (Abs(A2) <= eps)
319 A2 = 0.;
320
321 if (Abs(A3) <= eps)
322 A3 = 0.;
323 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
324 X = A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X();
325 Y = A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y();
326 Z = A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z();
327 if (!((Nv + 2) % 4 == 0 || (Nv + 3) % 4 == 0))
328 { X = - X; Y = - Y; Z = - Z; }
329 }
330 else {
331 if (IsOdd (Nu) &&
332 IsOdd (Nv)) {
333 Standard_Real RSinV = MinorRadius * sin(V);
334 A1 = RSinV * SinU; A2 = - RSinV * CosU;
335 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
336 if (Abs(A1) <= eps)
337 A1 = 0.;
338
339 if (Abs(A2) <= eps)
340 A2 = 0.;
341 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
342 X = A1 * XDir.X() + A2 * YDir.X();
343 Y = A1 * XDir.Y() + A2 * YDir.Y();
344 Z = A1 * XDir.Z() + A2 * YDir.Z();
345 }
346 else if (IsEven (Nu) && IsEven (Nv)) {
347 Standard_Real RCosV = MinorRadius * cos(V);
348 A1 = RCosV * CosU; A2 = RCosV * SinU;
349 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
350 if (Abs(A1) <= eps)
351 A1 = 0.;
352
353 if (Abs(A2) <= eps)
354 A2 = 0.;
355 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
356 X = A1 * XDir.X() + A2 * YDir.X();
357 Y = A1 * XDir.Y() + A2 * YDir.Y();
358 Z = A1 * XDir.Z() + A2 * YDir.Z();
359 }
360 else if (IsEven (Nv) && IsOdd (Nu)) {
361 Standard_Real RCosV = MinorRadius * cos(V);
362 A1 = RCosV * SinU; A2 = - RCosV * CosU;
363 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
364 if (Abs(A1) <= eps)
365 A1 = 0.;
366
367 if (Abs(A2) <= eps)
368 A2 = 0.;
369 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
370 X = A1 * XDir.X() + A2 * YDir.X();
371 Y = A1 * XDir.Y() + A2 * YDir.Y();
372 Z = A1 * XDir.Z() + A2 * YDir.Z();
373 if (((Nv + Nu + 3) % 4) == 0)
374 { X = - X; Y = - Y; Z = - Z; }
375 }
376 else if (IsOdd (Nv) && IsEven (Nu)) {
377 Standard_Real RSinV = MinorRadius * sin(V);
378 A1 = RSinV * CosU; A2 = RSinV * SinU;
379 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
380 if (Abs(A1) <= eps)
381 A1 = 0.;
382
383 if (Abs(A2) <= eps)
384 A2 = 0.;
385 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
386 X = A1 * XDir.X() + A2 * YDir.X();
387 Y = A1 * XDir.Y() + A2 * YDir.Y();
388 Z = A1 * XDir.Z() + A2 * YDir.Z();
389 if (((Nu + Nv + 3) % 4) == 0)
390 { X = - X; Y = - Y; Z = - Z; }
391 }
392 }
393 return gp_Vec (X,Y,Z);
394}
395
396void ElSLib::PlaneD0 (const Standard_Real U,
397 const Standard_Real V,
398 const gp_Ax3& Pos,
399 gp_Pnt& P)
400{
401 const gp_XYZ& XDir = Pos.XDirection().XYZ();
402 const gp_XYZ& YDir = Pos.YDirection().XYZ();
403 const gp_XYZ& PLoc = Pos.Location ().XYZ();
404 P.SetX(U * XDir.X() + V * YDir.X() + PLoc.X());
405 P.SetY(U * XDir.Y() + V * YDir.Y() + PLoc.Y());
406 P.SetZ(U * XDir.Z() + V * YDir.Z() + PLoc.Z());
407}
408
409void ElSLib::ConeD0 (const Standard_Real U,
410 const Standard_Real V,
411 const gp_Ax3& Pos,
412 const Standard_Real Radius,
413 const Standard_Real SAngle,
414 gp_Pnt& P)
415{
416 const gp_XYZ& XDir = Pos.XDirection().XYZ();
417 const gp_XYZ& YDir = Pos.YDirection().XYZ();
418 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
419 const gp_XYZ& PLoc = Pos.Location ().XYZ();
420 Standard_Real R = Radius + V * sin(SAngle);
421 Standard_Real A3 = V * cos(SAngle);
422 Standard_Real A1 = R * cos(U);
423 Standard_Real A2 = R * sin(U);
424 P.SetX(A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X() + PLoc.X());
425 P.SetY(A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y() + PLoc.Y());
426 P.SetZ(A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z() + PLoc.Z());
427}
428
429void ElSLib::CylinderD0 (const Standard_Real U,
430 const Standard_Real V,
431 const gp_Ax3& Pos,
432 const Standard_Real Radius,
433 gp_Pnt& P)
434{
435 const gp_XYZ& XDir = Pos.XDirection().XYZ();
436 const gp_XYZ& YDir = Pos.YDirection().XYZ();
437 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
438 const gp_XYZ& PLoc = Pos.Location ().XYZ();
439 Standard_Real A1 = Radius * cos(U);
440 Standard_Real A2 = Radius * sin(U);
441 P.SetX(A1 * XDir.X() + A2 * YDir.X() + V * ZDir.X() + PLoc.X());
442 P.SetY(A1 * XDir.Y() + A2 * YDir.Y() + V * ZDir.Y() + PLoc.Y());
443 P.SetZ(A1 * XDir.Z() + A2 * YDir.Z() + V * ZDir.Z() + PLoc.Z());
444}
445
446void ElSLib::SphereD0 (const Standard_Real U,
447 const Standard_Real V,
448 const gp_Ax3& Pos,
449 const Standard_Real Radius, gp_Pnt& P)
450{
451 const gp_XYZ& XDir = Pos.XDirection().XYZ();
452 const gp_XYZ& YDir = Pos.YDirection().XYZ();
453 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
454 const gp_XYZ& PLoc = Pos.Location ().XYZ();
455 Standard_Real R = Radius * cos(V);
456 Standard_Real A3 = Radius * sin(V);
457 Standard_Real A1 = R * cos(U);
458 Standard_Real A2 = R * sin(U);
459 P.SetX(A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X() + PLoc.X());
460 P.SetY(A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y() + PLoc.Y());
461 P.SetZ(A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z() + PLoc.Z());
462}
463
464void ElSLib::TorusD0 (const Standard_Real U,
465 const Standard_Real V,
466 const gp_Ax3& Pos,
467 const Standard_Real MajorRadius,
468 const Standard_Real MinorRadius,
469 gp_Pnt& P )
470{
471 const gp_XYZ& XDir = Pos.XDirection().XYZ();
472 const gp_XYZ& YDir = Pos.YDirection().XYZ();
473 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
474 const gp_XYZ& PLoc = Pos.Location ().XYZ();
475 Standard_Real R = MajorRadius + MinorRadius * cos(V);
476 Standard_Real A3 = MinorRadius * sin(V);
477 Standard_Real A1 = R * cos(U);
478 Standard_Real A2 = R * sin(U);
479 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
480 Standard_Real eps = 10.*(MinorRadius + MajorRadius)*RealEpsilon();
481
482 if (Abs(A1) <= eps)
483 A1 = 0.;
484
485 if (Abs(A2) <= eps)
486 A2 = 0.;
487
488 if (Abs(A3) <= eps)
489 A3 = 0.;
490 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
491 P.SetX(A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X() + PLoc.X());
492 P.SetY(A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y() + PLoc.Y());
493 P.SetZ(A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z() + PLoc.Z());
494}
495
496void ElSLib::PlaneD1 (const Standard_Real U,
497 const Standard_Real V,
498 const gp_Ax3& Pos,
499 gp_Pnt& P,
500 gp_Vec& Vu,
501 gp_Vec& Vv)
502{
503 const gp_XYZ& XDir = Pos.XDirection().XYZ();
504 const gp_XYZ& YDir = Pos.YDirection().XYZ();
505 const gp_XYZ& PLoc = Pos.Location ().XYZ();
506 P.SetX(U * XDir.X() + V * YDir.X() + PLoc.X());
507 P.SetY(U * XDir.Y() + V * YDir.Y() + PLoc.Y());
508 P.SetZ(U * XDir.Z() + V * YDir.Z() + PLoc.Z());
509 Vu.SetX(XDir.X());
510 Vu.SetY(XDir.Y());
511 Vu.SetZ(XDir.Z());
512 Vv.SetX(YDir.X());
513 Vv.SetY(YDir.Y());
514 Vv.SetZ(YDir.Z());
515}
516
517void ElSLib::ConeD1 (const Standard_Real U,
518 const Standard_Real V,
519 const gp_Ax3& Pos,
520 const Standard_Real Radius,
521 const Standard_Real SAngle,
522 gp_Pnt& P,
523 gp_Vec& Vu,
524 gp_Vec& Vv)
525{
526 // Z = V * Cos(SAngle)
527 // M(U,V) = Location() + V * Cos(SAngle) * ZDirection() +
528 // (Radius + V*Sin(SAng)) * (Cos(U) * XDirection() + Sin(U) * YDirection())
529
530 // D1U =
531 //(Radius + V*Sin(SAng)) * (-Sin(U) * XDirection() + Cos(U) * YDirection())
532
533 // D1V =
534 // Direction() *Cos(SAngle) + Sin(SAng) * (Cos(U) * XDirection() +
535 // Sin(U) * YDirection())
536
537 const gp_XYZ& XDir = Pos.XDirection().XYZ();
538 const gp_XYZ& YDir = Pos.YDirection().XYZ();
539 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
540 const gp_XYZ& PLoc = Pos.Location ().XYZ();
541 Standard_Real CosU = cos(U);
542 Standard_Real SinU = sin(U);
543 Standard_Real CosA = cos(SAngle);
544 Standard_Real SinA = sin(SAngle);
545 Standard_Real R = Radius + V * SinA;
546 Standard_Real A3 = V * CosA;
547 Standard_Real A1 = R * CosU;
548 Standard_Real A2 = R * SinU;
549 Standard_Real R1 = SinA * CosU;
550 Standard_Real R2 = SinA * SinU;
551 P .SetX( A1 * XDir.X() + A2 * YDir.X() + A3 * ZDir.X() + PLoc.X());
552 P .SetY( A1 * XDir.Y() + A2 * YDir.Y() + A3 * ZDir.Y() + PLoc.Y());
553 P .SetZ( A1 * XDir.Z() + A2 * YDir.Z() + A3 * ZDir.Z() + PLoc.Z());
554 Vu.SetX(- A2 * XDir.X() + A1 * YDir.X());
555 Vu.SetY(- A2 * XDir.Y() + A1 * YDir.Y());
556 Vu.SetZ(- A2 * XDir.Z() + A1 * YDir.Z());
557 Vv.SetX( R1 * XDir.X() + R2 * YDir.X() + CosA * ZDir.X());
558 Vv.SetY( R1 * XDir.Y() + R2 * YDir.Y() + CosA * ZDir.Y());
559 Vv.SetZ( R1 * XDir.Z() + R2 * YDir.Z() + CosA * ZDir.Z());
560}
561
562void ElSLib::CylinderD1 (const Standard_Real U,
563 const Standard_Real V,
564 const gp_Ax3& Pos,
565 const Standard_Real Radius,
566 gp_Pnt& P,
567 gp_Vec& Vu,
568 gp_Vec& Vv)
569{
570 const gp_XYZ& XDir = Pos.XDirection().XYZ();
571 const gp_XYZ& YDir = Pos.YDirection().XYZ();
572 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
573 const gp_XYZ& PLoc = Pos.Location ().XYZ();
574 Standard_Real A1 = Radius * cos(U);
575 Standard_Real A2 = Radius * sin(U);
576 P .SetX( A1 * XDir.X() + A2 * YDir.X() + V * ZDir.X() + PLoc.X());
577 P .SetY( A1 * XDir.Y() + A2 * YDir.Y() + V * ZDir.Y() + PLoc.Y());
578 P .SetZ( A1 * XDir.Z() + A2 * YDir.Z() + V * ZDir.Z() + PLoc.Z());
579 Vu.SetX(- A2 * XDir.X() + A1 * YDir.X());
580 Vu.SetY(- A2 * XDir.Y() + A1 * YDir.Y());
581 Vu.SetZ(- A2 * XDir.Z() + A1 * YDir.Z());
582 Vv.SetX( ZDir.X());
583 Vv.SetY( ZDir.Y());
584 Vv.SetZ( ZDir.Z());
585}
586
587void ElSLib::SphereD1 (const Standard_Real U,
588 const Standard_Real V,
589 const gp_Ax3& Pos,
590 const Standard_Real Radius,
591 gp_Pnt& P,
592 gp_Vec& Vu,
593 gp_Vec& Vv)
594{
595 // Vxy = CosU * XDirection + SinU * YDirection
596 // DVxy = -SinU * XDirection + CosU * YDirection
597
598 // P(U,V) = Location + R * CosV * Vxy + R * SinV * Direction
599
600 // Vu = R * CosV * DVxy
601
602 // Vv = -R * SinV * Vxy + R * CosV * Direction
603
604 const gp_XYZ& XDir = Pos.XDirection().XYZ();
605 const gp_XYZ& YDir = Pos.YDirection().XYZ();
606 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
607 const gp_XYZ& PLoc = Pos.Location ().XYZ();
608 Standard_Real CosU = cos(U);
609 Standard_Real SinU = sin(U);
610 Standard_Real R1 = Radius * cos(V);
611 Standard_Real R2 = Radius * sin(V);
612 Standard_Real A1 = R1 * CosU;
613 Standard_Real A2 = R1 * SinU;
614 Standard_Real A3 = R2 * CosU;
615 Standard_Real A4 = R2 * SinU;
616 P .SetX( A1 * XDir.X() + A2 * YDir.X() + R2 * ZDir.X() + PLoc.X());
617 P .SetY( A1 * XDir.Y() + A2 * YDir.Y() + R2 * ZDir.Y() + PLoc.Y());
618 P .SetZ( A1 * XDir.Z() + A2 * YDir.Z() + R2 * ZDir.Z() + PLoc.Z());
619 Vu.SetX(- A2 * XDir.X() + A1 * YDir.X());
620 Vu.SetY(- A2 * XDir.Y() + A1 * YDir.Y());
621 Vu.SetZ(- A2 * XDir.Z() + A1 * YDir.Z());
622 Vv.SetX(- A3 * XDir.X() - A4 * YDir.X() + R1 * ZDir.X());
623 Vv.SetY(- A3 * XDir.Y() - A4 * YDir.Y() + R1 * ZDir.Y());
624 Vv.SetZ(- A3 * XDir.Z() - A4 * YDir.Z() + R1 * ZDir.Z());
625}
626
627void ElSLib::TorusD1 ( const Standard_Real U,
628 const Standard_Real V,
629 const gp_Ax3& Pos,
630 const Standard_Real MajorRadius,
631 const Standard_Real MinorRadius,
632 gp_Pnt& P,
633 gp_Vec& Vu,
634 gp_Vec& Vv)
635{
636
637 //P(U,V) =
638 // Location +
639 // (MajorRadius+MinorRadius*Cos(V)) *
640 // (Cos(U)*XDirection + Sin(U)*YDirection) +
641 // MinorRadius * Sin(V) * Direction
642
643 //Vv = -MinorRadius * Sin(V) * (Cos(U)*XDirection + Sin(U)*YDirection) +
644 // MinorRadius * Cos(V) * Direction
645
646 //Vu =
647 // (MajorRadius+MinorRadius*Cos(V)) *
648 // (-Sin(U)*XDirection + Cos(U)*YDirection)
649
650 const gp_XYZ& XDir = Pos.XDirection().XYZ();
651 const gp_XYZ& YDir = Pos.YDirection().XYZ();
652 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
653 const gp_XYZ& PLoc = Pos.Location ().XYZ();
654 Standard_Real CosU = cos(U);
655 Standard_Real SinU = sin(U);
656 Standard_Real R1 = MinorRadius * cos(V);
657 Standard_Real R2 = MinorRadius * sin(V);
658 Standard_Real R = MajorRadius + R1;
659 Standard_Real A1 = R * CosU;
660 Standard_Real A2 = R * SinU;
661 Standard_Real A3 = R2 * CosU;
662 Standard_Real A4 = R2 * SinU;
663 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
664 Standard_Real eps = 10.*(MinorRadius + MajorRadius)*RealEpsilon();
665
666 if (Abs(A1) <= eps)
667 A1 = 0.;
668
669 if (Abs(A2) <= eps)
670 A2 = 0.;
671
672 if (Abs(A3) <= eps)
673 A3 = 0.;
674
675 if (Abs(A4) <= eps)
676 A4 = 0.;
677 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
678 P .SetX( A1 * XDir.X() + A2 * YDir.X() + R2 * ZDir.X() + PLoc.X());
679 P .SetY( A1 * XDir.Y() + A2 * YDir.Y() + R2 * ZDir.Y() + PLoc.Y());
680 P .SetZ( A1 * XDir.Z() + A2 * YDir.Z() + R2 * ZDir.Z() + PLoc.Z());
681 Vu.SetX(- A2 * XDir.X() + A1 * YDir.X());
682 Vu.SetY(- A2 * XDir.Y() + A1 * YDir.Y());
683 Vu.SetZ(- A2 * XDir.Z() + A1 * YDir.Z());
684 Vv.SetX(- A3 * XDir.X() - A4 * YDir.X() + R1 * ZDir.X());
685 Vv.SetY(- A3 * XDir.Y() - A4 * YDir.Y() + R1 * ZDir.Y());
686 Vv.SetZ(- A3 * XDir.Z() - A4 * YDir.Z() + R1 * ZDir.Z());
687}
688
689void ElSLib::ConeD2 (const Standard_Real U,
690 const Standard_Real V,
691 const gp_Ax3& Pos,
692 const Standard_Real Radius,
693 const Standard_Real SAngle,
694 gp_Pnt& P,
695 gp_Vec& Vu,
696 gp_Vec& Vv,
697 gp_Vec& Vuu,
698 gp_Vec& Vvv,
699 gp_Vec& Vuv)
700{
701 // Z = V * Cos(SAngle)
702 // M(U,V) = Location() + V * Cos(SAngle) * Direction() +
703 // (Radius + V*Sin(SAng)) * (Cos(U) * XDirection() + Sin(U) * YDirection())
704
705 // DU =
706 //(Radius + V*Sin(SAng)) * (-Sin(U) * XDirection() + Cos(U) * YDirection())
707
708 // DV =
709 // Direction() *Cos(SAngle) + Sin(SAng) * (Cos(U) * XDirection() +
710 // Sin(U) * YDirection())
711
712 // D2U =
713 //(Radius + V*Sin(SAng)) * (-Cos(U) * XDirection() - Sin(U) * YDirection())
714
715 // D2V = 0.0
716
717 // DUV =
718 //Sin(SAng) * (-Sin(U) * XDirection() + Cos(U) * YDirection())
719
720 const gp_XYZ& XDir = Pos.XDirection().XYZ();
721 const gp_XYZ& YDir = Pos.YDirection().XYZ();
722 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
723 const gp_XYZ& PLoc = Pos.Location ().XYZ();
724 Standard_Real CosU = cos(U);
725 Standard_Real SinU = sin(U);
726 Standard_Real CosA = cos(SAngle);
727 Standard_Real SinA = sin(SAngle);
728 Standard_Real R = Radius + V * SinA;
729 Standard_Real A3 = V * CosA;
730 Standard_Real A1 = R * CosU;
731 Standard_Real A2 = R * SinU;
732 Standard_Real R1 = SinA * CosU;
733 Standard_Real R2 = SinA * SinU;
734 Standard_Real Som1X = A1 * XDir.X() + A2 * YDir.X();
735 Standard_Real Som1Y = A1 * XDir.Y() + A2 * YDir.Y();
736 Standard_Real Som1Z = A1 * XDir.Z() + A2 * YDir.Z();
737 P .SetX( Som1X + A3 * ZDir.X() + PLoc.X());
738 P .SetY( Som1Y + A3 * ZDir.Y() + PLoc.Y());
739 P .SetZ( Som1Z + A3 * ZDir.Z() + PLoc.Z());
740 Vu .SetX(- A2 * XDir.X() + A1 * YDir.X());
741 Vu .SetY(- A2 * XDir.Y() + A1 * YDir.Y());
742 Vu .SetZ(- A2 * XDir.Z() + A1 * YDir.Z());
743 Vv .SetX( R1 * XDir.X() + R2 * YDir.X() + CosA * ZDir.X());
744 Vv .SetY( R1 * XDir.Y() + R2 * YDir.Y() + CosA * ZDir.Y());
745 Vv .SetZ( R1 * XDir.Z() + R2 * YDir.Z() + CosA * ZDir.Z());
746 Vuu.SetX(- Som1X);
747 Vuu.SetY(- Som1Y);
748 Vuu.SetZ(- Som1Z);
749 Vvv.SetX( 0.0);
750 Vvv.SetY( 0.0);
751 Vvv.SetZ( 0.0);
752 Vuv.SetX(- R2 * XDir.X() + R1 * YDir.X());
753 Vuv.SetY(- R2 * XDir.Y() + R1 * YDir.Y());
754 Vuv.SetZ(- R2 * XDir.Z() + R1 * YDir.Z());
755}
756
757void ElSLib::CylinderD2 (const Standard_Real U,
758 const Standard_Real V,
759 const gp_Ax3& Pos,
760 const Standard_Real Radius,
761 gp_Pnt& P,
762 gp_Vec& Vu,
763 gp_Vec& Vv,
764 gp_Vec& Vuu,
765 gp_Vec& Vvv,
766 gp_Vec& Vuv)
767{
768 const gp_XYZ& XDir = Pos.XDirection().XYZ();
769 const gp_XYZ& YDir = Pos.YDirection().XYZ();
770 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
771 const gp_XYZ& PLoc = Pos.Location ().XYZ();
772 Standard_Real A1 = Radius * cos(U);
773 Standard_Real A2 = Radius * sin(U);
774 Standard_Real Som1X = A1 * XDir.X() + A2 * YDir.X();
775 Standard_Real Som1Y = A1 * XDir.Y() + A2 * YDir.Y();
776 Standard_Real Som1Z = A1 * XDir.Z() + A2 * YDir.Z();
777 P .SetX( Som1X + V * ZDir.X() + PLoc.X());
778 P .SetY( Som1Y + V * ZDir.Y() + PLoc.Y());
779 P .SetZ( Som1Z + V * ZDir.Z() + PLoc.Z());
780 Vu .SetX(- A2 * XDir.X() + A1 * YDir.X());
781 Vu .SetY(- A2 * XDir.Y() + A1 * YDir.Y());
782 Vu .SetZ(- A2 * XDir.Z() + A1 * YDir.Z());
783 Vv .SetX( ZDir.X());
784 Vv .SetY( ZDir.Y());
785 Vv .SetZ( ZDir.Z());
786 Vuu.SetX(- Som1X);
787 Vuu.SetY(- Som1Y);
788 Vuu.SetZ(- Som1Z);
789 Vvv.SetX( 0.0);
790 Vvv.SetY( 0.0);
791 Vvv.SetZ( 0.0);
792 Vuv.SetX( 0.0);
793 Vuv.SetY( 0.0);
794 Vuv.SetZ( 0.0);
795}
796
797void ElSLib::SphereD2 (const Standard_Real U,
798 const Standard_Real V,
799 const gp_Ax3& Pos,
800 const Standard_Real Radius,
801 gp_Pnt& P,
802 gp_Vec& Vu,
803 gp_Vec& Vv,
804 gp_Vec& Vuu,
805 gp_Vec& Vvv,
806 gp_Vec& Vuv)
807{
808 // Vxy = CosU * XDirection + SinU * YDirection
809 // DVxy = -SinU * XDirection + CosU * YDirection
810
811 // P(U,V) = Location + R * CosV * Vxy + R * SinV * Direction
812
813 // Vu = R * CosV * DVxy
814
815 // Vuu = - R * CosV * Vxy
816
817 // Vv = -R * SinV * Vxy + R * CosV * Direction
818
819 // Vvv = -R * CosV * Vxy - R * SinV * Direction
820
821 // Vuv = - R * SinV * DVxy
822
823 const gp_XYZ& XDir = Pos.XDirection().XYZ();
824 const gp_XYZ& YDir = Pos.YDirection().XYZ();
825 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
826 const gp_XYZ& PLoc = Pos.Location ().XYZ();
827 Standard_Real CosU = cos(U);
828 Standard_Real SinU = sin(U);
829 Standard_Real R1 = Radius * cos(V);
830 Standard_Real R2 = Radius * sin(V);
831 Standard_Real A1 = R1 * CosU;
832 Standard_Real A2 = R1 * SinU;
833 Standard_Real A3 = R2 * CosU;
834 Standard_Real A4 = R2 * SinU;
835 Standard_Real Som1X = A1 * XDir.X() + A2 * YDir.X();
836 Standard_Real Som1Y = A1 * XDir.Y() + A2 * YDir.Y();
837 Standard_Real Som1Z = A1 * XDir.Z() + A2 * YDir.Z();
838 Standard_Real R2ZX = R2 * ZDir.X();
839 Standard_Real R2ZY = R2 * ZDir.Y();
840 Standard_Real R2ZZ = R2 * ZDir.Z();
841 P .SetX( Som1X + R2ZX + PLoc.X());
842 P .SetY( Som1Y + R2ZY + PLoc.Y());
843 P .SetZ( Som1Z + R2ZZ + PLoc.Z());
844 Vu .SetX(- A2 * XDir.X() + A1 * YDir.X());
845 Vu .SetY(- A2 * XDir.Y() + A1 * YDir.Y());
846 Vu .SetZ(- A2 * XDir.Z() + A1 * YDir.Z());
847 Vv .SetX(- A3 * XDir.X() - A4 * YDir.X() + R1 * ZDir.X());
848 Vv .SetY(- A3 * XDir.Y() - A4 * YDir.Y() + R1 * ZDir.Y());
849 Vv .SetZ(- A3 * XDir.Z() - A4 * YDir.Z() + R1 * ZDir.Z());
850 Vuu.SetX(- Som1X);
851 Vuu.SetY(- Som1Y);
852 Vuu.SetZ(- Som1Z);
853 Vvv.SetX(- Som1X - R2ZX);
854 Vvv.SetY(- Som1Y - R2ZY);
855 Vvv.SetZ(- Som1Z - R2ZZ);
856 Vuv.SetX( A4 * XDir.X() - A3 * YDir.X());
857 Vuv.SetY( A4 * XDir.Y() - A3 * YDir.Y());
858 Vuv.SetZ( A4 * XDir.Z() - A3 * YDir.Z());
859}
860
861void ElSLib::TorusD2 (const Standard_Real U,
862 const Standard_Real V,
863 const gp_Ax3& Pos,
864 const Standard_Real MajorRadius,
865 const Standard_Real MinorRadius,
866 gp_Pnt& P,
867 gp_Vec& Vu,
868 gp_Vec& Vv,
869 gp_Vec& Vuu,
870 gp_Vec& Vvv,
871 gp_Vec& Vuv)
872{
873 //P(U,V) =
874 // Location +
875 // (MajorRadius+MinorRadius*Cos(V)) *
876 // (Cos(U)*XDirection + Sin(U)*YDirection) +
877 // MinorRadius * Sin(V) * Direction
878
879 //Vv = -MinorRadius * Sin(V) * (Cos(U)*XDirection + Sin(U)*YDirection) +
880 // MinorRadius * Cos(V) * Direction
881
882 //Vu =
883 // (MajorRadius+MinorRadius*Cos(V)) *
884 // (-Sin(U)*XDirection + Cos(U)*YDirection)
885
886
887 //Vvv = -MinorRadius * Cos(V) * (Cos(U)*XDirection + Sin(U)*YDirection)
888 // -MinorRadius * Sin(V) * Direction
889
890 //Vuu =
891 // -(MajorRadius+MinorRadius*Cos(V)) *
892 // (Cos(U)*XDirection + Sin(U)*YDirection)
893
894 //Vuv = MinorRadius * Sin(V) * (Sin(U)*XDirection - Cos(U)*YDirection)
895
896 const gp_XYZ& XDir = Pos.XDirection().XYZ();
897 const gp_XYZ& YDir = Pos.YDirection().XYZ();
898 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
899 const gp_XYZ& PLoc = Pos.Location ().XYZ();
900 Standard_Real CosU = cos(U);
901 Standard_Real SinU = sin(U);
902 Standard_Real R1 = MinorRadius * cos(V);
903 Standard_Real R2 = MinorRadius * sin(V);
904 Standard_Real R = MajorRadius + R1;
905 Standard_Real A1 = R * CosU;
906 Standard_Real A2 = R * SinU;
907 Standard_Real A3 = R2 * CosU;
908 Standard_Real A4 = R2 * SinU;
909 Standard_Real A5 = R1 * CosU;
910 Standard_Real A6 = R1 * SinU;
911 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
912 Standard_Real eps = 10.*(MinorRadius + MajorRadius)*RealEpsilon();
913
914 if (Abs(A1) <= eps)
915 A1 = 0.;
916
917 if (Abs(A2) <= eps)
918 A2 = 0.;
919
920 if (Abs(A3) <= eps)
921 A3 = 0.;
922
923 if (Abs(A4) <= eps)
924 A4 = 0.;
925
926 if (Abs(A5) <= eps)
927 A5 = 0.;
928
929 if (Abs(A6) <= eps)
930 A6 = 0.;
931 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
932 Standard_Real Som1X = A1 * XDir.X() + A2 * YDir.X();
933 Standard_Real Som1Y = A1 * XDir.Y() + A2 * YDir.Y();
934 Standard_Real Som1Z = A1 * XDir.Z() + A2 * YDir.Z();
935 Standard_Real R2ZX = R2 * ZDir.X();
936 Standard_Real R2ZY = R2 * ZDir.Y();
937 Standard_Real R2ZZ = R2 * ZDir.Z();
938 P .SetX( Som1X + R2ZX + PLoc.X());
939 P .SetY( Som1Y + R2ZY + PLoc.Y());
940 P .SetZ( Som1Z + R2ZZ + PLoc.Z());
941 Vu .SetX(- A2 * XDir.X() + A1 * YDir.X());
942 Vu .SetY(- A2 * XDir.Y() + A1 * YDir.Y());
943 Vu .SetZ(- A2 * XDir.Z() + A1 * YDir.Z());
944 Vv .SetX(- A3 * XDir.X() - A4 * YDir.X() + R1 * ZDir.X());
945 Vv .SetY(- A3 * XDir.Y() - A4 * YDir.Y() + R1 * ZDir.Y());
946 Vv .SetZ(- A3 * XDir.Z() - A4 * YDir.Z() + R1 * ZDir.Z());
947 Vuu.SetX(- Som1X);
948 Vuu.SetY(- Som1Y);
949 Vuu.SetZ(- Som1Z);
950 Vvv.SetX(- A5 * XDir.X() - A6 * YDir.X() - R2ZX);
951 Vvv.SetY(- A5 * XDir.Y() - A6 * YDir.Y() - R2ZY);
952 Vvv.SetZ(- A5 * XDir.Z() - A6 * YDir.Z() - R2ZZ);
953 Vuv.SetX( A4 * XDir.X() - A3 * YDir.X());
954 Vuv.SetY( A4 * XDir.Y() - A3 * YDir.Y());
955 Vuv.SetZ( A4 * XDir.Z() - A3 * YDir.Z());
956}
957
958void ElSLib::ConeD3 (const Standard_Real U,
959 const Standard_Real V,
960 const gp_Ax3& Pos,
961 const Standard_Real Radius,
962 const Standard_Real SAngle,
963 gp_Pnt& P,
964 gp_Vec& Vu, gp_Vec& Vv,
965 gp_Vec& Vuu, gp_Vec& Vvv, gp_Vec& Vuv,
966 gp_Vec& Vuuu, gp_Vec& Vvvv,
967 gp_Vec& Vuuv, gp_Vec& Vuvv)
968{
969 // Z = V * Cos(SAngle)
970 // M(U,V) = Location() + V * Cos(SAngle) * Direction() +
971 // (Radius + V*Sin(SAng)) * (Cos(U) * XDirection() + Sin(U) * YDirection())
972
973 // DU =
974 //(Radius + V*Sin(SAng)) * (-Sin(U) * XDirection() + Cos(U) * YDirection())
975
976 // DV =
977 // Direction() *Cos(SAngle) + Sin(SAng) * (Cos(U) * XDirection() +
978 // Sin(U) * YDirection())
979
980 // D2U =
981 //(Radius + V*Sin(SAng)) * (-Cos(U) * XDirection() - Sin(U) * YDirection())
982
983 // D2V = 0.0
984
985 // DUV =
986 //Sin(SAng) * (-Sin(U) * XDirection() + Cos(U) * YDirection())
987
988 // D3U =
989 //(Radius + V*Sin(SAng)) * (Sin(U) * XDirection() - Cos(U) * YDirection())
990
991 // DUVV = 0.0
992
993 // D3V = 0.0
994
995 // DUUV = Sin(SAng) * (-Cos(U)*XDirection()-Sin(U) * YDirection()) +
996
997
998 const gp_XYZ& XDir = Pos.XDirection().XYZ();
999 const gp_XYZ& YDir = Pos.YDirection().XYZ();
1000 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
1001 const gp_XYZ& PLoc = Pos.Location ().XYZ();
1002 Standard_Real CosU = cos(U);
1003 Standard_Real SinU = sin(U);
1004 Standard_Real CosA = cos(SAngle);
1005 Standard_Real SinA = sin(SAngle);
1006 Standard_Real R = Radius + V * SinA;
1007 Standard_Real A3 = V * CosA;
1008 Standard_Real A1 = R * CosU;
1009 Standard_Real A2 = R * SinU;
1010 Standard_Real R1 = SinA * CosU;
1011 Standard_Real R2 = SinA * SinU;
1012 Standard_Real Som1X = A1 * XDir.X() + A2 * YDir.X();
1013 Standard_Real Som1Y = A1 * XDir.Y() + A2 * YDir.Y();
1014 Standard_Real Som1Z = A1 * XDir.Z() + A2 * YDir.Z();
1015 Standard_Real Som2X = R1 * XDir.X() + R2 * YDir.X();
1016 Standard_Real Som2Y = R1 * XDir.Y() + R2 * YDir.Y();
1017 Standard_Real Som2Z = R1 * XDir.Z() + R2 * YDir.Z();
1018 Standard_Real Dif1X = A2 * XDir.X() - A1 * YDir.X();
1019 Standard_Real Dif1Y = A2 * XDir.Y() - A1 * YDir.Y();
1020 Standard_Real Dif1Z = A2 * XDir.Z() - A1 * YDir.Z();
1021 P .SetX( Som1X + A3 * ZDir.X() + PLoc.X());
1022 P .SetY( Som1Y + A3 * ZDir.Y() + PLoc.Y());
1023 P .SetZ( Som1Z + A3 * ZDir.Z() + PLoc.Z());
1024 Vu .SetX(- Dif1X);
1025 Vu .SetY(- Dif1Y);
1026 Vu .SetZ(- Dif1Z);
1027 Vv .SetX( Som2X + CosA * ZDir.X());
1028 Vv .SetY( Som2Y + CosA * ZDir.Y());
1029 Vv .SetZ( Som2Z + CosA * ZDir.Z());
1030 Vuu .SetX(- Som1X);
1031 Vuu .SetY(- Som1Y);
1032 Vuu .SetZ(- Som1Z);
1033 Vvv .SetX( 0.0);
1034 Vvv .SetY( 0.0);
1035 Vvv .SetZ( 0.0);
1036 Vuv .SetX(- R2 * XDir.X() + R1 * YDir.X());
1037 Vuv .SetY(- R2 * XDir.Y() + R1 * YDir.Y());
1038 Vuv .SetZ(- R2 * XDir.Z() + R1 * YDir.Z());
1039 Vuuu.SetX( Dif1X);
1040 Vuuu.SetY( Dif1Y);
1041 Vuuu.SetZ( Dif1Z);
1042 Vvvv.SetX( 0.0);
1043 Vvvv.SetY( 0.0);
1044 Vvvv.SetZ( 0.0);
1045 Vuvv.SetX( 0.0);
1046 Vuvv.SetY( 0.0);
1047 Vuvv.SetZ( 0.0);
1048 Vuuv.SetX(- Som2X);
1049 Vuuv.SetY(- Som2Y);
1050 Vuuv.SetZ(- Som2Z);
1051}
1052
1053void ElSLib::CylinderD3 (const Standard_Real U,
1054 const Standard_Real V,
1055 const gp_Ax3& Pos,
1056 const Standard_Real Radius,
1057 gp_Pnt& P,
1058 gp_Vec& Vu, gp_Vec& Vv,
1059 gp_Vec& Vuu, gp_Vec& Vvv, gp_Vec& Vuv,
1060 gp_Vec& Vuuu, gp_Vec& Vvvv,
1061 gp_Vec& Vuuv, gp_Vec& Vuvv)
1062{
1063 const gp_XYZ& XDir = Pos.XDirection().XYZ();
1064 const gp_XYZ& YDir = Pos.YDirection().XYZ();
1065 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
1066 const gp_XYZ& PLoc = Pos.Location ().XYZ();
1067 Standard_Real A1 = Radius * cos(U);
1068 Standard_Real A2 = Radius * sin(U);
1069 Standard_Real Som1X = A1 * XDir.X() + A2 * YDir.X();
1070 Standard_Real Som1Y = A1 * XDir.Y() + A2 * YDir.Y();
1071 Standard_Real Som1Z = A1 * XDir.Z() + A2 * YDir.Z();
1072 Standard_Real Dif1X = A2 * XDir.X() - A1 * YDir.X();
1073 Standard_Real Dif1Y = A2 * XDir.Y() - A1 * YDir.Y();
1074 Standard_Real Dif1Z = A2 * XDir.Z() - A1 * YDir.Z();
1075 P .SetX( Som1X + V * ZDir.X() + PLoc.X());
1076 P .SetY( Som1Y + V * ZDir.Y() + PLoc.Y());
1077 P .SetZ( Som1Z + V * ZDir.Z() + PLoc.Z());
1078 Vu .SetX(- Dif1X);
1079 Vu .SetY(- Dif1Y);
1080 Vu .SetZ(- Dif1Z);
1081 Vv .SetX( ZDir.X());
1082 Vv .SetY( ZDir.Y());
1083 Vv .SetZ( ZDir.Z());
1084 Vuu .SetX(- Som1X);
1085 Vuu .SetY(- Som1Y);
1086 Vuu .SetZ(- Som1Z);
1087 Vvv .SetX( 0.0);
1088 Vvv .SetY( 0.0);
1089 Vvv .SetZ( 0.0);
1090 Vuv .SetX( 0.0);
1091 Vuv .SetY( 0.0);
1092 Vuv .SetZ( 0.0);
1093 Vuuu.SetX( Dif1X);
1094 Vuuu.SetY( Dif1Y);
1095 Vuuu.SetZ( Dif1Z);
1096 Vvvv.SetX( 0.0);
1097 Vvvv.SetY( 0.0);
1098 Vvvv.SetZ( 0.0);
1099 Vuvv.SetX( 0.0);
1100 Vuvv.SetY( 0.0);
1101 Vuvv.SetZ( 0.0);
1102 Vuuv.SetX( 0.0);
1103 Vuuv.SetY( 0.0);
1104 Vuuv.SetZ( 0.0);
1105}
1106
1107void ElSLib::SphereD3 (const Standard_Real U,
1108 const Standard_Real V,
1109 const gp_Ax3& Pos,
1110 const Standard_Real Radius,
1111 gp_Pnt& P,
1112 gp_Vec& Vu, gp_Vec& Vv,
1113 gp_Vec& Vuu, gp_Vec& Vvv, gp_Vec& Vuv,
1114 gp_Vec& Vuuu, gp_Vec& Vvvv,
1115 gp_Vec& Vuuv, gp_Vec& Vuvv)
1116{
1117
1118 // Vxy = CosU * XDirection + SinU * YDirection
1119 // DVxy = -SinU * XDirection + CosU * YDirection
1120
1121 // P(U,V) = Location + R * CosV * Vxy + R * SinV * Direction
1122
1123 // Vu = R * CosV * DVxy
1124
1125 // Vuu = - R * CosV * Vxy
1126
1127 // Vuuu = - Vu
1128
1129 // Vv = -R * SinV * Vxy + R * CosV * Direction
1130
1131 // Vvv = -R * CosV * Vxy - R * SinV * Direction
1132
1133 // Vvvv = -Vv
1134
1135 // Vuv = - R * SinV * DVxy
1136
1137 // Vuuv = R * SinV * Vxy
1138
1139 // Vuvv = - R * CosV * DVxy = Vuuu = -Vu
1140
1141 const gp_XYZ& XDir = Pos.XDirection().XYZ();
1142 const gp_XYZ& YDir = Pos.YDirection().XYZ();
1143 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
1144 const gp_XYZ& PLoc = Pos.Location ().XYZ();
1145 Standard_Real CosU = cos(U);
1146 Standard_Real SinU = sin(U);
1147 Standard_Real R1 = Radius * cos(V);
1148 Standard_Real R2 = Radius * sin(V);
1149 Standard_Real A1 = R1 * CosU;
1150 Standard_Real A2 = R1 * SinU;
1151 Standard_Real A3 = R2 * CosU;
1152 Standard_Real A4 = R2 * SinU;
1153 Standard_Real Som1X = A1 * XDir.X() + A2 * YDir.X();
1154 Standard_Real Som1Y = A1 * XDir.Y() + A2 * YDir.Y();
1155 Standard_Real Som1Z = A1 * XDir.Z() + A2 * YDir.Z();
1156 Standard_Real Som3X = A3 * XDir.X() + A4 * YDir.X();
1157 Standard_Real Som3Y = A3 * XDir.Y() + A4 * YDir.Y();
1158 Standard_Real Som3Z = A3 * XDir.Z() + A4 * YDir.Z();
1159 Standard_Real Dif1X = A2 * XDir.X() - A1 * YDir.X();
1160 Standard_Real Dif1Y = A2 * XDir.Y() - A1 * YDir.Y();
1161 Standard_Real Dif1Z = A2 * XDir.Z() - A1 * YDir.Z();
1162 Standard_Real R1ZX = R1 * ZDir.X();
1163 Standard_Real R1ZY = R1 * ZDir.Y();
1164 Standard_Real R1ZZ = R1 * ZDir.Z();
1165 Standard_Real R2ZX = R2 * ZDir.X();
1166 Standard_Real R2ZY = R2 * ZDir.Y();
1167 Standard_Real R2ZZ = R2 * ZDir.Z();
1168 P .SetX( Som1X + R2ZX + PLoc.X());
1169 P .SetY( Som1Y + R2ZY + PLoc.Y());
1170 P .SetZ( Som1Z + R2ZZ + PLoc.Z());
1171 Vu .SetX(- Dif1X);
1172 Vu .SetY(- Dif1Y);
1173 Vu .SetZ(- Dif1Z);
1174 Vv .SetX(- Som3X + R1ZX);
1175 Vv .SetY(- Som3Y + R1ZY);
1176 Vv .SetZ(- Som3Z + R1ZZ);
1177 Vuu .SetX(- Som1X);
1178 Vuu .SetY(- Som1Y);
1179 Vuu .SetZ(- Som1Z);
1180 Vvv .SetX(- Som1X - R2ZX);
1181 Vvv .SetY(- Som1Y - R2ZY);
1182 Vvv .SetZ(- Som1Z - R2ZZ);
1183 Vuv .SetX( A4 * XDir.X() - A3 * YDir.X());
1184 Vuv .SetY( A4 * XDir.Y() - A3 * YDir.Y());
1185 Vuv .SetZ( A4 * XDir.Z() - A3 * YDir.Z());
1186 Vuuu.SetX( Dif1X);
1187 Vuuu.SetY( Dif1Y);
1188 Vuuu.SetZ( Dif1Z);
1189 Vvvv.SetX( Som3X - R1ZX);
1190 Vvvv.SetY( Som3Y - R1ZY);
1191 Vvvv.SetZ( Som3Z - R1ZZ);
1192 Vuvv.SetX( Dif1X);
1193 Vuvv.SetY( Dif1Y);
1194 Vuvv.SetZ( Dif1Z);
1195 Vuuv.SetX( Som3X);
1196 Vuuv.SetY( Som3Y);
1197 Vuuv.SetZ( Som3Z);
1198}
1199
1200void ElSLib::TorusD3 (const Standard_Real U,
1201 const Standard_Real V,
1202 const gp_Ax3& Pos,
1203 const Standard_Real MajorRadius,
1204 const Standard_Real MinorRadius,
1205 gp_Pnt& P,
1206 gp_Vec& Vu, gp_Vec& Vv,
1207 gp_Vec& Vuu, gp_Vec& Vvv, gp_Vec& Vuv,
1208 gp_Vec& Vuuu, gp_Vec& Vvvv,
1209 gp_Vec& Vuuv, gp_Vec& Vuvv)
1210{
1211
1212 //P(U,V) =
1213 // Location +
1214 // (MajorRadius+MinorRadius*Cos(V)) *
1215 // (Cos(U)*XDirection + Sin(U)*YDirection) +
1216 // MinorRadius * Sin(V) * Direction
1217
1218 //Vv = -MinorRadius * Sin(V) * (Cos(U)*XDirection + Sin(U)*YDirection) +
1219 // MinorRadius * Cos(V) * Direction
1220
1221 //Vvv = -MinorRadius * Cos(V) * (Cos(U)*XDirection + Sin(U)*YDirection)
1222 // -MinorRadius * Sin(V) * Direction
1223
1224 //Vvvv = - Vv
1225
1226 //Vu =
1227 // (MajorRadius+MinorRadius*Cos(V)) *
1228 // (-Sin(U)*XDirection + Cos(U)*YDirection)
1229
1230 //Vuu =
1231 // -(MajorRadius+MinorRadius*Cos(V)) *
1232 // (Cos(U)*XDirection + Sin(U)*YDirection)
1233
1234 //Vuuu = -Vu
1235
1236 //Vuv = MinorRadius * Sin(V) * (Sin(U)*XDirection - Cos(U)*YDirection)
1237
1238 //Vuvv = MinorRadius * Cos(V) * (Sin(U)*XDirection - Cos(U)*YDirection)
1239
1240 //Vuuv = MinorRadius * Sin(V) * (Cos(U)*XDirection + Sin(U)*YDirection)
1241
1242 const gp_XYZ& XDir = Pos.XDirection().XYZ();
1243 const gp_XYZ& YDir = Pos.YDirection().XYZ();
1244 const gp_XYZ& ZDir = Pos.Direction ().XYZ();
1245 const gp_XYZ& PLoc = Pos.Location ().XYZ();
1246 Standard_Real CosU = cos(U);
1247 Standard_Real SinU = sin(U);
1248 Standard_Real R1 = MinorRadius * cos(V);
1249 Standard_Real R2 = MinorRadius * sin(V);
1250 Standard_Real R = MajorRadius + R1;
1251 Standard_Real A1 = R * CosU;
1252 Standard_Real A2 = R * SinU;
1253 Standard_Real A3 = R2 * CosU;
1254 Standard_Real A4 = R2 * SinU;
1255 Standard_Real A5 = R1 * CosU;
1256 Standard_Real A6 = R1 * SinU;
1257 // Modified by skv - Tue Sep 9 15:10:34 2003 OCC620 Begin
1258 Standard_Real eps = 10.*(MinorRadius + MajorRadius)*RealEpsilon();
1259
1260 if (Abs(A1) <= eps)
1261 A1 = 0.;
1262
1263 if (Abs(A2) <= eps)
1264 A2 = 0.;
1265
1266 if (Abs(A3) <= eps)
1267 A3 = 0.;
1268
1269 if (Abs(A4) <= eps)
1270 A4 = 0.;
1271
1272 if (Abs(A5) <= eps)
1273 A5 = 0.;
1274
1275 if (Abs(A6) <= eps)
1276 A6 = 0.;
1277 // Modified by skv - Tue Sep 9 15:10:35 2003 OCC620 End
1278 Standard_Real Som1X = A1 * XDir.X() + A2 * YDir.X();
1279 Standard_Real Som1Y = A1 * XDir.Y() + A2 * YDir.Y();
1280 Standard_Real Som1Z = A1 * XDir.Z() + A2 * YDir.Z();
1281 Standard_Real Som3X = A3 * XDir.X() + A4 * YDir.X();
1282 Standard_Real Som3Y = A3 * XDir.Y() + A4 * YDir.Y();
1283 Standard_Real Som3Z = A3 * XDir.Z() + A4 * YDir.Z();
1284 Standard_Real Dif1X = A2 * XDir.X() - A1 * YDir.X();
1285 Standard_Real Dif1Y = A2 * XDir.Y() - A1 * YDir.Y();
1286 Standard_Real Dif1Z = A2 * XDir.Z() - A1 * YDir.Z();
1287 Standard_Real R1ZX = R1 * ZDir.X();
1288 Standard_Real R1ZY = R1 * ZDir.Y();
1289 Standard_Real R1ZZ = R1 * ZDir.Z();
1290 Standard_Real R2ZX = R2 * ZDir.X();
1291 Standard_Real R2ZY = R2 * ZDir.Y();
1292 Standard_Real R2ZZ = R2 * ZDir.Z();
1293 P .SetX( Som1X + R2ZX + PLoc.X());
1294 P .SetY( Som1Y + R2ZY + PLoc.Y());
1295 P .SetZ( Som1Z + R2ZZ + PLoc.Z());
1296 Vu .SetX(- Dif1X);
1297 Vu .SetY(- Dif1Y);
1298 Vu .SetZ(- Dif1Z);
1299 Vv .SetX(- Som3X + R1ZX);
1300 Vv .SetY(- Som3Y + R1ZY);
1301 Vv .SetZ(- Som3Z + R1ZZ);
1302 Vuu .SetX(- Som1X);
1303 Vuu .SetY(- Som1Y);
1304 Vuu .SetZ(- Som1Z);
1305 Vvv .SetX(- A5 * XDir.X() - A6 * YDir.X() - R2ZX);
1306 Vvv .SetY(- A5 * XDir.Y() - A6 * YDir.Y() - R2ZY);
1307 Vvv .SetZ(- A5 * XDir.Z() - A6 * YDir.Z() - R2ZZ);
1308 Vuv .SetX( A4 * XDir.X() - A3 * YDir.X());
1309 Vuv .SetY( A4 * XDir.Y() - A3 * YDir.Y());
1310 Vuv .SetZ( A4 * XDir.Z() - A3 * YDir.Z());
1311 Vuuu.SetX( Dif1X);
1312 Vuuu.SetY( Dif1Y);
1313 Vuuu.SetZ( Dif1Z);
1314 Vvvv.SetX( Som3X - R1ZX);
1315 Vvvv.SetY( Som3Y - R1ZY);
1316 Vvvv.SetZ( Som3Z - R1ZZ);
1317 Vuuv.SetX( Som3X);
1318 Vuuv.SetY( Som3Y);
1319 Vuuv.SetZ( Som3Z);
1320 Vuvv.SetX( A6 * XDir.X() - A5 * YDir.X() );
1321 Vuvv.SetY( A6 * XDir.Y() - A5 * YDir.Y() );
1322 Vuvv.SetZ( A6 * XDir.Z() - A5 * YDir.Z() );
1323}
1324
1325//=======================================================================
1326//function : PlaneParameters
1327//purpose :
1328//=======================================================================
1329
1330void ElSLib::PlaneParameters (const gp_Ax3& Pos,
1331 const gp_Pnt& P,
1332 Standard_Real& U,
1333 Standard_Real& V)
1334{
1335 gp_Trsf T;
1336 T.SetTransformation (Pos);
1337 gp_Pnt Ploc = P.Transformed (T);
1338 U = Ploc.X();
1339 V = Ploc.Y();
1340}
1341
1342//=======================================================================
1343//function : CylindreParameters
1344//purpose :
1345//=======================================================================
1346
1347void ElSLib::CylinderParameters (const gp_Ax3& Pos,
1348 const Standard_Real,
1349 const gp_Pnt& P,
1350 Standard_Real& U,
1351 Standard_Real& V)
1352{
1353 gp_Trsf T;
1354 T.SetTransformation (Pos);
1355 gp_Pnt Ploc = P.Transformed (T);
1356 U = atan2(Ploc.Y(),Ploc.X());
1357 if (U < -1.e-16) U += PIPI;
1358 else if (U < 0) U = 0;
1359 V = Ploc.Z();
1360}
1361
1362//=======================================================================
1363//function : ConeParameters
1364//purpose :
1365//=======================================================================
1366
1367void ElSLib::ConeParameters(const gp_Ax3& Pos,
1368 const Standard_Real Radius,
1369 const Standard_Real SAngle,
1370 const gp_Pnt& P,
1371 Standard_Real& U,
1372 Standard_Real& V)
1373{
1374 gp_Trsf T;
1375 T.SetTransformation (Pos);
1376 gp_Pnt Ploc = P.Transformed (T);
1377
1378 if(Ploc.X() ==0.0 && Ploc.Y()==0.0 ) {
1379 U = 0.0;
1380 }
1381 else if ( -Radius > Ploc.Z()* Tan(SAngle) ) {
0d969553 1382 // the point is at the wrong side of the apex
7fd59977 1383 U = atan2(-Ploc.Y(), -Ploc.X());
1384 }
1385 else {
1386 U = atan2(Ploc.Y(),Ploc.X());
1387 }
1388 if (U < -1.e-16) U += PIPI;
1389 else if (U < 0) U = 0;
1390
0d969553 1391 // Evaluate V as follows :
7fd59977 1392 // P0 = Cone.Value(U,0)
1393 // P1 = Cone.Value(U,1)
1394 // V = P0 P1 . P0 Ploc
0d969553 1395 // After simplification obtain:
7fd59977 1396 // V = Sin(Sang) * ( x cosU + y SinU - R) + z * Cos(Sang)
0d969553
Y
1397 // Method that permits to find V of the projected point if the point
1398 // is not actually on the cone.
7fd59977 1399
1400 V = sin(SAngle) * ( Ploc.X() * cos(U) + Ploc.Y() * sin(U) - Radius)
1401 + cos(SAngle) * Ploc.Z();
1402}
1403
1404//=======================================================================
1405//function : SphereParameters
1406//purpose :
1407//=======================================================================
1408
1409void ElSLib::SphereParameters(const gp_Ax3& Pos,
1410 const Standard_Real,
1411 const gp_Pnt& P,
1412 Standard_Real& U,
1413 Standard_Real& V)
1414{
1415 gp_Trsf T;
1416 T.SetTransformation (Pos);
1417 gp_Pnt Ploc = P.Transformed (T);
1418 Standard_Real x, y, z;
1419 Ploc.Coord (x, y, z);
1420 Standard_Real l = sqrt (x * x + y * y);
0d969553 1421 if (l < gp::Resolution()) { // point on axis Z of the sphere
7fd59977 1422 if (z > 0.)
1423 V = M_PI_2; // PI * 0.5
1424 else
1425 V = - M_PI_2; // PI * 0.5
1426 U = 0.;
1427 }
1428 else {
1429 V = atan(z/l);
1430 U = atan2(y,x);
1431 if (U < -1.e-16) U += PIPI;
1432 else if (U < 0) U = 0;
1433 }
1434}
1435
1436//=======================================================================
1437//function : TorusParameters
1438//purpose :
1439//=======================================================================
1440
1441void ElSLib::TorusParameters(const gp_Ax3& Pos,
1442 const Standard_Real MajorRadius,
1443 const Standard_Real MinorRadius,
1444 const gp_Pnt& P,
1445 Standard_Real& U,
1446 Standard_Real& V)
1447{
1448 gp_Trsf Tref;
1449 Tref.SetTransformation (Pos);
1450 gp_Pnt Ploc = P.Transformed (Tref);
1451 Standard_Real x, y, z;
1452 Ploc.Coord (x, y, z);
1453
0d969553 1454 // all that to process case of Major < Minor.
7fd59977 1455 U = atan2(y,x);
1456 if (MajorRadius < MinorRadius){
1457 Standard_Real cosu = cos(U);
1458 Standard_Real sinu = sin(U);
1459 Standard_Real z2 = z * z;
1460 Standard_Real MinR2 = MinorRadius * MinorRadius;
1461 Standard_Real RCosU = MajorRadius * cosu;
1462 Standard_Real RSinU = MajorRadius * sinu;
1463 Standard_Real xm = x - RCosU;
1464 Standard_Real ym = y - RSinU;
1465 Standard_Real xp = x + RCosU;
1466 Standard_Real yp = y + RSinU;
1467 Standard_Real D1 = xm * xm + ym * ym + z2 - MinR2;
1468 Standard_Real D2 = xp * xp + yp * yp + z2 - MinR2;
1469 Standard_Real AD1 = D1;
1470 if (AD1 < 0) AD1 = - AD1;
1471 Standard_Real AD2 = D2;
1472 if (AD2 < 0) AD2 = - AD2;
c6541a0c 1473 if (AD2 < AD1) U += M_PI;
7fd59977 1474 }
1475 if (U < -1.e-16) U += PIPI;
1476 else if (U < 0) U = 0;
1477 Standard_Real cosu = cos(U);
1478 Standard_Real sinu = sin(U);
1479 gp_Dir dx(cosu,sinu,0.);
e8e8b273 1480 gp_XYZ dPV(x - MajorRadius * cosu,
1481 y - MajorRadius * sinu,
1482 z);
1483 Standard_Real aMag = dPV.Modulus();
1484 if (aMag <= gp::Resolution())
1485 {
1486 V = 0.;
1487 }
1488 else
1489 {
1490 gp_Dir dP(dPV);
1491 V = dx.AngleWithRef(dP, dx^gp::DZ());
1492 }
7fd59977 1493 if (V < -1.e-16) V += PIPI;
1494 else if (V < 0) V = 0;
1495}
1496
1497//=======================================================================
1498//function : PlaneUIso
1499//purpose :
1500//=======================================================================
1501
1502gp_Lin ElSLib::PlaneUIso(const gp_Ax3& Pos,
1503 const Standard_Real U)
1504{
1505 gp_Lin L(Pos.Location(),Pos.YDirection());
1506 gp_Vec Ve(Pos.XDirection());
1507 Ve *= U;
1508 L.Translate(Ve);
1509 return L;
1510}
1511
1512//=======================================================================
1513//function : CylinderUIso
1514//purpose :
1515//=======================================================================
1516
1517gp_Lin ElSLib::CylinderUIso(const gp_Ax3& Pos,
1518 const Standard_Real Radius,
1519 const Standard_Real U)
1520{
1521 gp_Pnt P;
1522 gp_Vec DU,DV;
1523 CylinderD1(U,0.,Pos,Radius,P,DU,DV);
1524 gp_Lin L(P,DV);
1525 return L;
1526}
1527
1528//=======================================================================
1529//function : ConeUIso
1530//purpose :
1531//=======================================================================
1532
1533gp_Lin ElSLib::ConeUIso(const gp_Ax3& Pos,
1534 const Standard_Real Radius,
1535 const Standard_Real SAngle,
1536 const Standard_Real U)
1537{
1538 gp_Pnt P;
1539 gp_Vec DU,DV;
1540 ConeD1(U,0,Pos,Radius,SAngle,P,DU,DV);
1541 gp_Lin L(P,DV);
1542 return L;
1543}
1544
1545//=======================================================================
1546//function : SphereUIso
1547//purpose :
1548//=======================================================================
1549
1550gp_Circ ElSLib::SphereUIso(const gp_Ax3& Pos,
1551 const Standard_Real Radius,
1552 const Standard_Real U)
1553{
1554 gp_Vec dx = Pos.XDirection();
1555 gp_Vec dy = Pos.YDirection();
1556 gp_Dir dz = Pos.Direction ();
1557 gp_Dir cx = cos(U) * dx + sin(U) * dy;
1558 gp_Ax2 axes(Pos.Location(),
1559 cx.Crossed(dz),
1560 cx);
1561 gp_Circ Circ(axes,Radius);
1562 return Circ;
1563}
1564
1565//=======================================================================
1566//function : TorusUIso
1567//purpose :
1568//=======================================================================
1569
1570gp_Circ ElSLib::TorusUIso(const gp_Ax3& Pos,
1571 const Standard_Real MajorRadius,
1572 const Standard_Real MinorRadius,
1573 const Standard_Real U)
1574{
1575 gp_Vec dx = Pos.XDirection();
1576 gp_Vec dy = Pos.YDirection();
1577 gp_Dir dz = Pos.Direction ();
1578 gp_Dir cx = cos(U) * dx + sin(U) * dy;
1579 gp_Ax2 axes(Pos.Location(),
1580 cx.Crossed(dz),
1581 cx);
1582 gp_Vec Ve = cx;
1583 Ve *= MajorRadius;
1584 axes.Translate(Ve);
1585 gp_Circ Circ(axes,MinorRadius);
1586 return Circ;
1587}
1588
1589//=======================================================================
1590//function : PlaneVIso
1591//purpose :
1592//=======================================================================
1593
1594gp_Lin ElSLib::PlaneVIso(const gp_Ax3& Pos,
1595 const Standard_Real V)
1596{
1597 gp_Lin L(Pos.Location(),Pos.XDirection());
1598 gp_Vec Ve(Pos.YDirection());
1599 Ve *= V;
1600 L.Translate(Ve);
1601 return L;
1602}
1603
1604//=======================================================================
1605//function : CylinderVIso
1606//purpose :
1607//=======================================================================
1608
1609gp_Circ ElSLib::CylinderVIso(const gp_Ax3& Pos,
1610 const Standard_Real Radius,
1611 const Standard_Real V)
1612{
1613 gp_Ax2 axes = Pos.Ax2();
1614 gp_Vec Ve(Pos.Direction());
1615 Ve.Multiply(V);
1616 axes.Translate(Ve);
1617 gp_Circ C(axes,Radius);
1618 return C;
1619}
1620
1621//=======================================================================
1622//function : ConeVIso
1623//purpose :
1624//=======================================================================
1625
1626gp_Circ ElSLib::ConeVIso(const gp_Ax3& Pos,
1627 const Standard_Real Radius,
1628 const Standard_Real SAngle,
1629 const Standard_Real V)
1630{
1631 gp_Ax3 axes(Pos);
1632 gp_Vec Ve(Pos.Direction());
1633 Ve.Multiply(V * cos(SAngle));
1634 axes.Translate(Ve);
1635 Standard_Real R = Radius + V * sin(SAngle);
1636 if (R < 0) {
1637 axes.XReverse();
1638 axes.YReverse();
1639 R = - R;
1640 }
1641 gp_Circ C(axes.Ax2(),R);
1642 return C;
1643}
1644
1645//=======================================================================
1646//function : SphereVIso
1647//purpose :
1648//=======================================================================
1649
1650gp_Circ ElSLib::SphereVIso(const gp_Ax3& Pos,
1651 const Standard_Real Radius,
1652 const Standard_Real V)
1653{
1654 gp_Ax2 axes = Pos.Ax2();
1655 gp_Vec Ve(Pos.Direction());
1656 Ve.Multiply(Radius * sin(V));
1657 axes.Translate(Ve);
1658 Standard_Real radius = Radius * cos(V);
5554ac68 1659 // #23170: if V is even slightly (e.g. by double epsilon) greater than PI/2,
1660 // radius will become negative and constructor of gp_Circ will raise exception.
1661 // Lets try to create correct isoline even on analytical continuation for |V| > PI/2...
1662 if (radius < 0.)
1663 {
1664 axes.SetDirection (-axes.Direction());
1665 radius = -radius;
1666 }
7fd59977 1667 gp_Circ Circ(axes,radius);
1668 return Circ;
1669}
1670
1671//=======================================================================
1672//function : TorusVIso
1673//purpose :
1674//=======================================================================
1675
1676gp_Circ ElSLib::TorusVIso(const gp_Ax3& Pos,
1677 const Standard_Real MajorRadius,
1678 const Standard_Real MinorRadius,
1679 const Standard_Real V)
1680{
1681 gp_Ax3 axes = Pos.Ax2();
1682 gp_Vec Ve(Pos.Direction());
1683 Ve.Multiply(MinorRadius * sin(V));
1684 axes.Translate(Ve);
1685 Standard_Real R = MajorRadius + MinorRadius * cos(V);
1686 if (R < 0) {
1687 axes.XReverse();
1688 axes.YReverse();
1689 R = - R;
1690 }
1691 gp_Circ Circ(axes.Ax2(),R);
1692 return Circ;
1693}
1694