1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
17 #include <gp_Circ2d.hxx>
18 #include <gp_Elips2d.hxx>
19 #include <gp_Hypr2d.hxx>
20 #include <gp_Lin2d.hxx>
21 #include <gp_Parab2d.hxx>
22 #include <IntAna2d_AnaIntersection.hxx>
23 #include <IntAna2d_Conic.hxx>
24 #include <IntAna2d_IntPoint.hxx>
25 #include <Standard_OutOfRange.hxx>
26 #include <StdFail_NotDone.hxx>
28 //=======================================================================
31 //=======================================================================
32 void IntAna2d_AnaIntersection::Perform(const gp_Lin2d& L,
41 Standard_Real A,B,C0, d;
42 gp_Pnt2d aP2D, aP2D1, aP2D2;
44 L.Coefficients(A,B,C0);
45 d=A*C.Location().X() + B*C.Location().Y() + C0;
47 if (Abs(d)-C.Radius()>Epsilon(C.Radius())) {
51 else { // Au moins 1 solution
54 //modified by NIZNHY-PKV Fri Jun 15 09:55:00 2007f
56 //ang = C.XAxis().Direction().Angle(L.Direction());
57 //ang = ang + M_PI / 2.0;
58 //modified by NIZNHY-PKV Fri Jun 15 09:55:29 2007t
59 if (Abs(Abs(d)-C.Radius())<=Epsilon(C.Radius())) { // Cas de tangence
61 Standard_Real u, XS, YS, ang;
64 XS=C.Location().X() - d*A;
65 YS=C.Location().Y() - d*B;
67 //modified by NIZNHY-PKV Fri Jun 15 09:55:35 2007f
68 aP2D.SetCoord(XS, YS);
69 u=ElCLib::Parameter(L, aP2D);
70 ang=ElCLib::Parameter(C, aP2D);
72 u=B*(L.Location().X()-C.Location().X()) -
73 A*(L.Location().Y()-C.Location().Y());
74 if (d<0.0) {ang=ang+M_PI;}
82 //modified by NIZNHY-PKV Fri Jun 15 09:55:41 2007t
83 lpnt[0].SetValue(XS,YS,u,ang);
85 else { // 2 points d intersection
86 Standard_Real h, XS1,YS1, XS2,YS2, ang1,ang2, u1,u2;//,cost,sint angt;
88 h=Sqrt(C.Radius()*C.Radius()-d*d);
89 //modified by NIZNHY-PKV Fri Jun 15 09:55:47 2007f
92 //modified by NIZNHY-PKV Fri Jun 15 09:55:52 2007t
93 XS1=C.Location().X() - d*A - h*B;
94 YS1=C.Location().Y() - d*B + h*A;
95 XS2=C.Location().X() - d*A + h*B;
96 YS2=C.Location().Y() - d*B - h*A;
98 //modified by NIZNHY-PKV Fri Jun 15 09:55:57 2007f
99 aP2D1.SetCoord(XS1, YS1);
100 aP2D2.SetCoord(XS2, YS2);
101 u1=ElCLib::Parameter(L, aP2D1);
102 u2=ElCLib::Parameter(L, aP2D2);
103 ang1=ElCLib::Parameter(C, aP2D1);
104 ang2=ElCLib::Parameter(C, aP2D2);
107 if (Abs(cost)<=0.707) {
112 if (cost<0) {angt=M_PI-angt;}
120 else if (ang1>=2.0*M_PI) {
126 else if (ang2>=2.0*M_PI) {
130 u1=B*(L.Location().X()-C.Location().X()) -
131 A*(L.Location().Y()-C.Location().Y()) +h;
134 //modified by NIZNHY-PKV Fri Jun 15 09:56:19 2007t
135 lpnt[0].SetValue(XS1,YS1,u1,ang1);
136 lpnt[1].SetValue(XS2,YS2,u2,ang2);