0032969: Coding - get rid of unused headers [IMeshData to PLib]
[occt.git] / src / IntAna2d / IntAna2d_AnaIntersection_3.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <ElCLib.hxx>
17 #include <gp_Circ2d.hxx>
18 #include <gp_Lin2d.hxx>
19 #include <IntAna2d_AnaIntersection.hxx>
20 #include <IntAna2d_Conic.hxx>
21 #include <IntAna2d_IntPoint.hxx>
22
23 //=======================================================================
24 //function : Perform
25 //purpose  : 
26 //=======================================================================
27 void IntAna2d_AnaIntersection::Perform(const gp_Lin2d& L,
28                                        const gp_Circ2d& C) 
29 {
30  
31   done=Standard_False;
32
33   iden=Standard_False; 
34   para=Standard_False;
35   //
36   Standard_Real A,B,C0, d;
37   gp_Pnt2d aP2D, aP2D1, aP2D2;
38   //
39   L.Coefficients(A,B,C0);
40   d=A*C.Location().X() + B*C.Location().Y() + C0;
41   
42   if (Abs(d)-C.Radius()>Epsilon(C.Radius())) {
43     empt=Standard_True;
44     nbp=0;
45   }
46   else {                                       // Au moins 1 solution
47     empt=Standard_False;
48     //
49     //modified by NIZNHY-PKV Fri Jun 15 09:55:00 2007f
50     //Standard_Real ang;
51     //ang = C.XAxis().Direction().Angle(L.Direction());
52     //ang = ang + M_PI / 2.0;
53     //modified by NIZNHY-PKV Fri Jun 15 09:55:29 2007t
54     if (Abs(Abs(d)-C.Radius())<=Epsilon(C.Radius())) {    // Cas de tangence
55       
56       Standard_Real u, XS, YS, ang;
57       //
58       nbp=1;
59       XS=C.Location().X() - d*A;
60       YS=C.Location().Y() - d*B;
61       //
62       //modified by NIZNHY-PKV Fri Jun 15 09:55:35 2007f
63       aP2D.SetCoord(XS, YS);
64       u=ElCLib::Parameter(L, aP2D);
65       ang=ElCLib::Parameter(C, aP2D);
66       /*
67       u=B*(L.Location().X()-C.Location().X()) -
68         A*(L.Location().Y()-C.Location().Y());
69       if (d<0.0) {ang=ang+M_PI;}
70       if (ang>=2.0*M_PI) {
71         ang=ang-2.0*M_PI;
72       }
73       else if (ang<0.0) {
74         ang=ang+2.0*M_PI;
75       }
76       */
77       //modified by NIZNHY-PKV Fri Jun 15 09:55:41 2007t
78       lpnt[0].SetValue(XS,YS,u,ang);
79     }
80     else { // 2 points d intersection
81       Standard_Real h, XS1,YS1, XS2,YS2, ang1,ang2, u1,u2;//,cost,sint angt;                                        
82       nbp=2;
83       h=Sqrt(C.Radius()*C.Radius()-d*d);
84       //modified by NIZNHY-PKV Fri Jun 15 09:55:47 2007f
85       //cost=d/C.Radius();
86       //sint=h/C.Radius();
87       //modified by NIZNHY-PKV Fri Jun 15 09:55:52 2007t
88       XS1=C.Location().X() - d*A - h*B;
89       YS1=C.Location().Y() - d*B + h*A;
90       XS2=C.Location().X() - d*A + h*B;
91       YS2=C.Location().Y() - d*B - h*A;
92       //
93       //modified by NIZNHY-PKV Fri Jun 15 09:55:57 2007f
94       aP2D1.SetCoord(XS1, YS1);
95       aP2D2.SetCoord(XS2, YS2);
96       u1=ElCLib::Parameter(L, aP2D1);
97       u2=ElCLib::Parameter(L, aP2D2);
98       ang1=ElCLib::Parameter(C, aP2D1);
99       ang2=ElCLib::Parameter(C, aP2D2);
100       //
101       /*
102       if (Abs(cost)<=0.707) {
103         angt=ACos(cost);
104       }
105       else {
106         angt=ASin(sint);
107         if (cost<0) {angt=M_PI-angt;}
108       }
109       
110       ang1=ang-angt;
111       ang2=ang+angt;
112       if (ang1<0.0) {
113         ang1=ang1+2.0*M_PI;
114       }
115       else if (ang1>=2.0*M_PI) {
116         ang1=ang1-2.0*M_PI;
117       }
118       if (ang2<0.0) {
119         ang2=ang2+2.0*M_PI;
120       }
121       else if (ang2>=2.0*M_PI) {
122         ang2=ang2-2.0*M_PI;
123       }
124
125       u1=B*(L.Location().X()-C.Location().X()) -
126               A*(L.Location().Y()-C.Location().Y()) +h;
127       u2=u1-2.0*h;
128       */
129       //modified by NIZNHY-PKV Fri Jun 15 09:56:19 2007t
130       lpnt[0].SetValue(XS1,YS1,u1,ang1);
131       lpnt[1].SetValue(XS2,YS2,u2,ang2);
132     }
133   }
134   done=Standard_True;
135 }
136