1 // File Extrema_ExtElCS.cxx
3 // Modified by skv - Thu Jul 7 14:37:05 2005 OCC9134
5 #include <Extrema_ExtElCS.ixx>
6 #include <Extrema_ExtPElS.hxx>
7 #include <Extrema_ExtPElC.hxx>
8 #include <Extrema_ExtElC.hxx>
9 #include <Extrema_POnCurv.hxx>
10 #include <Standard_NotImplemented.hxx>
11 #include <StdFail_InfiniteSolutions.hxx>
12 #include <Precision.hxx>
18 Extrema_ExtElCS::Extrema_ExtElCS()
20 myDone = Standard_False;
21 myIsPar = Standard_False;
25 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
33 void Extrema_ExtElCS::Perform(const gp_Lin& C,
36 myDone = Standard_True;
37 myIsPar = Standard_False;
39 if (C.Direction().IsNormal(S.Axis().Direction(),
40 Precision::Angular())) {
41 mySqDist = new TColStd_HArray1OfReal(1, 1);
42 mySqDist->SetValue(1, S.SquareDistance(C));
43 myIsPar = Standard_True;
52 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
60 void Extrema_ExtElCS::Perform(const gp_Lin& C,
63 myDone = Standard_False;
65 myIsPar = Standard_False;
67 gp_Ax3 Pos = S.Position();
69 gp_Pnt O = Pos.Location();
73 Standard_Real radius = S.Radius();
74 Extrema_ExtElC Extrem(gp_Lin(Pos.Axis()), C, Precision::Angular());
75 if (Extrem.IsParallel()) {
76 mySqDist = new TColStd_HArray1OfReal(1, 1);
77 Standard_Real aDist = sqrt (Extrem.SquareDistance(1)) - radius;
78 mySqDist->SetValue(1, aDist * aDist);
79 myDone = Standard_True;
80 myIsPar = Standard_True;
84 if (Extrem.IsDone()) {
85 Extrema_POnCurv myPOnC1, myPOnC2;
86 Extrem.Points(1, myPOnC1, myPOnC2);
87 gp_Pnt PC = myPOnC2.Value();
89 if ((gp_Lin(Pos.Axis())).Contains(PC, Precision::Confusion())) {
90 gp_Dir D = C.Direction();
91 gp_Vec Dp(-D.Dot(Pos.YDirection()), D.Dot(Pos.XDirection()), 0.0);
93 gp_Pnt P1(PC.Translated(radius*Dp));
94 gp_Pnt P2(PC.Translated(-radius*Dp));
97 mySqDist = new TColStd_HArray1OfReal(1, myNbExt);
98 myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt);
99 myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt);
100 ElSLib::CylinderParameters(Pos, radius, P1, U, V);
101 Extrema_POnSurf P1S(U, V, P1);
102 ElSLib::CylinderParameters(Pos, radius, P2, U, V);
103 Extrema_POnSurf P2S(U, V, P2);
104 mySqDist->SetValue(1, PC.SquareDistance(P1));
105 mySqDist->SetValue(2, PC.SquareDistance(P2));
106 myPoint1->SetValue(1, myPOnC2);
107 myPoint1->SetValue(2, myPOnC2);
108 myPoint2->SetValue(1, P1S);
109 myPoint2->SetValue(2, P2S);
112 Extrema_ExtPElS ExPS(myPOnC2.Value(), S, Precision::Confusion());
114 myNbExt = ExPS.NbExt();
115 mySqDist = new TColStd_HArray1OfReal(1, myNbExt);
116 myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt);
117 myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt);
118 for (i = 1; i <= myNbExt; i++) {
119 myPoint1->SetValue(i, myPOnC2);
120 myPoint2->SetValue(i, ExPS.Point(i));
121 mySqDist->SetValue(i,(myPOnC2.Value()).SquareDistance(ExPS.Point(i).Value()));
125 myDone = Standard_True;
133 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
141 //void Extrema_ExtElCS::Perform(const gp_Lin& C,
143 void Extrema_ExtElCS::Perform(const gp_Lin& ,
146 Standard_NotImplemented::Raise();
152 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
160 void Extrema_ExtElCS::Perform(const gp_Lin& C,
163 myDone = Standard_False;
165 myIsPar = Standard_False;
167 gp_Pnt O = S.Location();
169 Extrema_ExtPElC Extrem(O, C, Precision::Angular(), RealFirst(), RealLast());
172 if (Extrem.IsDone()) {
173 Extrema_POnCurv myPOnC1 = Extrem.Point(1);
174 Extrema_ExtPElS ExPS(myPOnC1.Value(), S, Precision::Confusion());
176 myNbExt = ExPS.NbExt();
177 mySqDist = new TColStd_HArray1OfReal(1, myNbExt);
178 myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt);
179 myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt);
180 for (i = 1; i <= myNbExt; i++) {
181 myPoint1->SetValue(i, myPOnC1);
182 myPoint2->SetValue(i, ExPS.Point(i));
183 mySqDist->SetValue(i,(myPOnC1.Value()).SquareDistance(ExPS.Point(i).Value()));
184 myDone = Standard_True;
191 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Lin& C,
199 //void Extrema_ExtElCS::Perform(const gp_Lin& C,
200 // const gp_Torus& S)
201 void Extrema_ExtElCS::Perform(const gp_Lin& ,
204 Standard_NotImplemented::Raise();
211 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
219 //void Extrema_ExtElCS::Perform(const gp_Circ& C,
221 void Extrema_ExtElCS::Perform(const gp_Circ& ,
224 Standard_NotImplemented::Raise();
230 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
231 const gp_Cylinder& S)
238 // Modified by skv - Thu Jul 7 14:37:05 2005 OCC9134 Begin
239 // Implementation of the method.
240 void Extrema_ExtElCS::Perform(const gp_Circ& C,
241 const gp_Cylinder& S)
243 myDone = Standard_False;
244 myIsPar = Standard_False;
247 // Get an axis line of the cylinder.
248 gp_Lin anAxis(S.Axis());
250 // Compute extrema between the circle and the line.
251 Extrema_ExtElC anExtC(anAxis, C, 0.);
253 if (anExtC.IsDone()) {
254 if (anExtC.IsParallel()) {
255 myIsPar = Standard_True;
256 mySqDist = new TColStd_HArray1OfReal(1, 1);
257 Standard_Real aDist = sqrt (anExtC.SquareDistance(1)) - S.Radius();
258 mySqDist->SetValue(1, aDist * aDist);
260 Standard_Integer aNbExt = anExtC.NbExt();
261 gp_Pnt aCenter = C.Location();
263 Standard_Integer aCurI = 1;
264 Standard_Real aTolConf = Precision::Confusion();
265 Standard_Real aCylRad = S.Radius();
267 // Compute the extremas.
269 mySqDist = new TColStd_HArray1OfReal(1, myNbExt);
270 myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt);
271 myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt);
273 for (i = 1; i <= aNbExt; i++) {
274 Extrema_POnCurv aPOnAxis;
275 Extrema_POnCurv aPOnCirc;
276 Standard_Real aSqDist = anExtC.SquareDistance(i);
277 Standard_Real aDist = sqrt (aSqDist);
279 anExtC.Points(i, aPOnAxis, aPOnCirc);
281 if (aSqDist <= (aTolConf * aTolConf) || aCenter.IsEqual(aPOnAxis.Value(), aTolConf)) {
286 gp_Dir aDir(aPOnAxis.Value().XYZ().
287 Subtracted(aPOnCirc.Value().XYZ()));
288 Standard_Real aShift[2] = { aDist + aCylRad, aDist - aCylRad };
291 for (j = 0; j < 2; j++) {
295 aVec.Multiply(aShift[j]);
296 aPntOnCyl = aPOnCirc.Value().Translated(aVec);
301 ElSLib::Parameters(S, aPntOnCyl, aU, aV);
303 Extrema_POnSurf aPOnSurf(aU, aV, aPntOnCyl);
305 myPoint1->SetValue(aCurI, aPOnCirc);
306 myPoint2->SetValue(aCurI, aPOnSurf);
307 mySqDist->SetValue(aCurI++, aShift[j] * aShift[j]);
312 myDone = Standard_True;
315 // Modified by skv - Thu Jul 7 14:37:05 2005 OCC9134 End
319 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
327 //void Extrema_ExtElCS::Perform(const gp_Circ& C,
329 void Extrema_ExtElCS::Perform(const gp_Circ& ,
332 Standard_NotImplemented::Raise();
338 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
346 //void Extrema_ExtElCS::Perform(const gp_Circ& C,
347 // const gp_Sphere& S)
348 void Extrema_ExtElCS::Perform(const gp_Circ& ,
351 Standard_NotImplemented::Raise();
355 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Circ& C,
363 //void Extrema_ExtElCS::Perform(const gp_Circ& C,
364 // const gp_Torus& S)
365 void Extrema_ExtElCS::Perform(const gp_Circ& ,
368 Standard_NotImplemented::Raise();
372 Extrema_ExtElCS::Extrema_ExtElCS(const gp_Hypr& C,
380 void Extrema_ExtElCS::Perform(const gp_Hypr& C,
383 myDone = Standard_True;
384 myIsPar = Standard_False;
386 gp_Ax2 Pos = C.Position();
387 gp_Dir NHypr = Pos.Direction();
388 gp_Dir NPln = S.Axis().Direction();
390 if (NHypr.IsParallel(NPln, Precision::Angular())) {
392 mySqDist = new TColStd_HArray1OfReal(1, 1);
393 mySqDist->SetValue(1, S.SquareDistance(C.Location()));
394 myIsPar = Standard_True;
399 gp_Dir XDir = Pos.XDirection();
400 gp_Dir YDir = Pos.YDirection();
402 Standard_Real A = C.MinorRadius()*(NPln.Dot(YDir));
403 Standard_Real B = C.MajorRadius()*(NPln.Dot(XDir));
405 if(Abs(B) > Abs(A)) {
406 Standard_Real T = -0.5 * Log((A+B)/(B-A));
407 gp_Pnt Ph = ElCLib::HyperbolaValue(T, Pos, C.MajorRadius(), C.MinorRadius());
408 Extrema_POnCurv PC(T, Ph);
409 myPoint1 = new Extrema_HArray1OfPOnCurv(1,1);
410 myPoint1->SetValue(1, PC);
412 mySqDist = new TColStd_HArray1OfReal(1, 1);
413 mySqDist->SetValue(1, S.SquareDistance(Ph));
416 ElSLib::PlaneParameters(S.Position(), Ph, U, V);
417 gp_Pnt Pp = ElSLib::PlaneValue(U, V, S.Position());
418 Extrema_POnSurf PS(U, V, Pp);
419 myPoint2 = new Extrema_HArray1OfPOnSurf(1,1);
420 myPoint2->SetValue(1, PS);
433 Standard_Boolean Extrema_ExtElCS::IsDone() const
439 Standard_Integer Extrema_ExtElCS::NbExt() const
441 if (myIsPar) StdFail_InfiniteSolutions::Raise();
445 Standard_Real Extrema_ExtElCS::SquareDistance(const Standard_Integer N) const
447 if (myIsPar && N != 1) StdFail_InfiniteSolutions::Raise();
448 return mySqDist->Value(N);
452 void Extrema_ExtElCS::Points(const Standard_Integer N,
454 Extrema_POnSurf& P2) const
456 if (myIsPar) StdFail_InfiniteSolutions::Raise();
457 P1 = myPoint1->Value(N);
458 P2 = myPoint2->Value(N);
462 Standard_Boolean Extrema_ExtElCS::IsParallel() const