b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
7fd59977 |
15 | |
16 | #include <ElCLib.hxx> |
42cf5bc1 |
17 | #include <GccAna_Circ2d3Tan.hxx> |
7fd59977 |
18 | #include <GccAna_Lin2dBisec.hxx> |
42cf5bc1 |
19 | #include <GccAna_LinPnt2dBisec.hxx> |
20 | #include <GccEnt_BadQualifier.hxx> |
21 | #include <GccEnt_QualifiedCirc.hxx> |
22 | #include <GccEnt_QualifiedLin.hxx> |
7fd59977 |
23 | #include <GccInt_BLine.hxx> |
24 | #include <GccInt_BParab.hxx> |
42cf5bc1 |
25 | #include <GccInt_IType.hxx> |
26 | #include <gp_Circ2d.hxx> |
27 | #include <gp_Dir2d.hxx> |
28 | #include <gp_Lin2d.hxx> |
29 | #include <gp_Pnt2d.hxx> |
30 | #include <IntAna2d_AnaIntersection.hxx> |
7fd59977 |
31 | #include <IntAna2d_Conic.hxx> |
42cf5bc1 |
32 | #include <IntAna2d_IntPoint.hxx> |
33 | #include <Standard_OutOfRange.hxx> |
34 | #include <StdFail_NotDone.hxx> |
7fd59977 |
35 | |
36 | //========================================================================= |
0d969553 |
37 | // Creation of a circle tangent to two straight lines and a point. + |
7fd59977 |
38 | //========================================================================= |
7fd59977 |
39 | GccAna_Circ2d3Tan:: |
40 | GccAna_Circ2d3Tan (const GccEnt_QualifiedLin& Qualified1 , |
41 | const GccEnt_QualifiedLin& Qualified2 , |
42 | const gp_Pnt2d& Point3 , |
43 | const Standard_Real Tolerance ): |
44 | |
45 | cirsol(1,2) , |
46 | qualifier1(1,2) , |
47 | qualifier2(1,2) , |
48 | qualifier3(1,2) , |
49 | TheSame1(1,2) , |
50 | TheSame2(1,2) , |
51 | TheSame3(1,2) , |
52 | pnttg1sol(1,2) , |
53 | pnttg2sol(1,2) , |
54 | pnttg3sol(1,2) , |
55 | par1sol(1,2) , |
56 | par2sol(1,2) , |
57 | par3sol(1,2) , |
58 | pararg1(1,2) , |
59 | pararg2(1,2) , |
60 | pararg3(1,2) |
61 | { |
62 | |
63 | gp_Dir2d dirx(1.0,0.0); |
64 | WellDone = Standard_False; |
65 | Standard_Real Tol = Abs(Tolerance); |
66 | NbrSol = 0; |
67 | if (!(Qualified1.IsEnclosed() || |
68 | Qualified1.IsOutside() || Qualified1.IsUnqualified()) || |
69 | !(Qualified2.IsEnclosed() || |
70 | Qualified2.IsOutside() || Qualified2.IsUnqualified())) { |
71 | GccEnt_BadQualifier::Raise(); |
72 | return; |
73 | } |
74 | |
75 | pnttg3sol.Init(Point3); |
76 | |
77 | //========================================================================= |
0d969553 |
78 | // Processing. + |
7fd59977 |
79 | //========================================================================= |
80 | |
81 | gp_Lin2d L1 = Qualified1.Qualified(); |
82 | gp_Lin2d L2 = Qualified2.Qualified(); |
83 | gp_Pnt2d origin1(L1.Location()); |
84 | gp_Dir2d dir1(L1.Direction()); |
85 | gp_Dir2d normL1(-dir1.Y(),dir1.X()); |
86 | gp_Pnt2d origin2(L2.Location()); |
87 | gp_Dir2d dir2(L2.Direction()); |
88 | gp_Dir2d normL2(-dir2.Y(),dir2.X()); |
89 | |
90 | GccAna_Lin2dBisec Bis1(L1,L2); |
91 | GccAna_LinPnt2dBisec Bis2(L1,Point3); |
92 | if (Bis1.IsDone() && Bis2.IsDone()) { |
93 | Standard_Integer nbsolution1 = Bis1.NbSolutions(); |
94 | Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution(); |
95 | for (Standard_Integer i = 1 ; i <= nbsolution1; i++) { |
0797d9d3 |
96 | #ifdef OCCT_DEBUG |
7fd59977 |
97 | gp_Lin2d Sol1(Bis1.ThisSolution(i)); |
98 | #else |
99 | Bis1.ThisSolution(i) ; |
100 | #endif |
101 | GccInt_IType typ2 = Sol2->ArcType(); |
102 | IntAna2d_AnaIntersection Intp; |
103 | if (typ2 == GccInt_Lin) { |
104 | Intp.Perform(Bis1.ThisSolution(i),Sol2->Line()); |
105 | } |
106 | else if (typ2 == GccInt_Par) { |
107 | Intp.Perform(Bis1.ThisSolution(i),IntAna2d_Conic(Sol2->Parabola())); |
108 | } |
109 | if (Intp.IsDone()) { |
110 | if (!Intp.IsEmpty()) { |
111 | for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) { |
112 | gp_Pnt2d Center(Intp.Point(j).Value()); |
113 | Standard_Real dist1 = L1.Distance(Center); |
114 | Standard_Real dist2 = L2.Distance(Center); |
115 | Standard_Real dist3 = Center.Distance(Point3); |
116 | Standard_Real Radius=0; |
7fd59977 |
117 | Standard_Integer nbsol3 = 0; |
118 | Standard_Boolean ok = Standard_False; |
119 | if (Qualified1.IsEnclosed()) { |
120 | if ((((origin1.X()-Center.X())*(-dir1.Y()))+ |
121 | ((origin1.Y()-Center.Y())*(dir1.X())))<=0){ |
122 | ok = Standard_True; |
7fd59977 |
123 | Radius = dist1; |
124 | } |
125 | } |
126 | else if (Qualified1.IsOutside()) { |
127 | if ((((origin1.X()-Center.X())*(-dir1.Y()))+ |
128 | ((origin1.Y()-Center.Y())*(dir1.X())))>=0){ |
129 | ok = Standard_True; |
7fd59977 |
130 | Radius = dist1; |
131 | } |
132 | } |
133 | else if (Qualified1.IsUnqualified()) { |
134 | ok = Standard_True; |
7fd59977 |
135 | Radius = dist1; |
136 | } |
137 | if (Qualified2.IsEnclosed()) { |
138 | if ((((origin2.X()-Center.X())*(-dir2.Y()))+ |
139 | ((origin2.Y()-Center.Y())*(dir2.X())))<=0){ |
96a95605 |
140 | if (Abs(dist2-Radius) < Tol) { } |
7fd59977 |
141 | else { ok = Standard_False; } |
142 | } |
143 | } |
144 | else if (Qualified2.IsOutside() && ok) { |
145 | if ((((origin2.X()-Center.X())*(-dir2.Y()))+ |
146 | ((origin2.Y()-Center.Y())*(dir2.X())))>=0){ |
96a95605 |
147 | if (Abs(dist2-Radius) < Tol) { } |
7fd59977 |
148 | else { ok = Standard_False; } |
149 | } |
150 | } |
151 | else if (Qualified2.IsUnqualified() && ok) { |
96a95605 |
152 | if (Abs(dist2-Radius) < Tol) { } |
7fd59977 |
153 | else { ok = Standard_False; } |
154 | } |
155 | if (ok) { |
156 | if (Abs(dist3-Radius) < Tol) { nbsol3 = 1; } |
157 | else { ok = Standard_False; } |
158 | } |
159 | if (ok) { |
160 | for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) { |
161 | NbrSol++; |
162 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius); |
163 | // ======================================================= |
164 | gp_Dir2d dc1(origin1.XY()-Center.XY()); |
165 | if (!Qualified1.IsUnqualified()) { |
166 | qualifier1(NbrSol) = Qualified1.Qualifier(); |
167 | } |
168 | else if (dc1.Dot(normL1) > 0.0) { |
169 | qualifier1(NbrSol) = GccEnt_outside; |
170 | } |
171 | else { qualifier1(NbrSol) = GccEnt_enclosed; } |
172 | gp_Dir2d dc2(origin2.XY()-Center.XY()); |
173 | if (!Qualified2.IsUnqualified()) { |
174 | qualifier2(NbrSol) = Qualified2.Qualifier(); |
175 | } |
176 | else if (dc2.Dot(normL2) > 0.0) { |
177 | qualifier2(NbrSol) = GccEnt_outside; |
178 | } |
179 | else { qualifier2(NbrSol) = GccEnt_enclosed; } |
180 | qualifier3(NbrSol) = GccEnt_noqualifier; |
181 | TheSame1(NbrSol) = 0; |
182 | gp_Dir2d dc(origin1.XY()-Center.XY()); |
183 | Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X())); |
184 | dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X())); |
185 | pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY()); |
186 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
187 | pnttg1sol(NbrSol)); |
188 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); |
189 | TheSame2(NbrSol) = 0; |
190 | dc = gp_Dir2d(origin2.XY()-Center.XY()); |
191 | sign = dc.Dot(gp_Dir2d(-dir2.Y(),dir2.X())); |
192 | dc = gp_Dir2d(sign*gp_XY(-dir2.Y(),dir2.X())); |
193 | pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY()); |
194 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
195 | pnttg2sol(NbrSol)); |
196 | pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol)); |
197 | TheSame3(NbrSol) = 0; |
198 | par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
199 | pnttg3sol(NbrSol)); |
200 | pararg3(NbrSol) = 0.; |
201 | } |
202 | } |
203 | } |
204 | } |
205 | WellDone = Standard_True; |
206 | } |
207 | } |
208 | } |
209 | } |
210 | |