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 | |
7fd59977 |
16 | #include <ElCLib.hxx> |
42cf5bc1 |
17 | #include <GccAna_Circ2d3Tan.hxx> |
7fd59977 |
18 | #include <GccAna_CircLin2dBisec.hxx> |
19 | #include <GccAna_Lin2dBisec.hxx> |
42cf5bc1 |
20 | #include <GccEnt_BadQualifier.hxx> |
21 | #include <GccEnt_QualifiedCirc.hxx> |
22 | #include <GccEnt_QualifiedLin.hxx> |
7fd59977 |
23 | #include <GccInt_BParab.hxx> |
42cf5bc1 |
24 | #include <GccInt_IType.hxx> |
25 | #include <gp_Circ2d.hxx> |
26 | #include <gp_Dir2d.hxx> |
27 | #include <gp_Lin2d.hxx> |
28 | #include <gp_Pnt2d.hxx> |
29 | #include <IntAna2d_AnaIntersection.hxx> |
7fd59977 |
30 | #include <IntAna2d_Conic.hxx> |
42cf5bc1 |
31 | #include <IntAna2d_IntPoint.hxx> |
42cf5bc1 |
32 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 |
33 | |
34 | //========================================================================= |
0d969553 |
35 | // Creation of a circle tangent to a circle and two straight lines. + |
7fd59977 |
36 | //========================================================================= |
7fd59977 |
37 | GccAna_Circ2d3Tan::GccAna_Circ2d3Tan (const GccEnt_QualifiedCirc& Qualified1 , |
38 | const GccEnt_QualifiedLin& Qualified2 , |
39 | const GccEnt_QualifiedLin& Qualified3 , |
40 | const Standard_Real Tolerance ) |
41 | |
42 | //========================================================================= |
0d969553 |
43 | // Initialisation of fields. + |
7fd59977 |
44 | //========================================================================= |
45 | |
46 | :cirsol(1,8) , |
47 | qualifier1(1,8) , |
48 | qualifier2(1,8) , |
49 | qualifier3(1,8) , |
50 | TheSame1(1,8) , |
51 | TheSame2(1,8) , |
52 | TheSame3(1,8) , |
53 | pnttg1sol(1,8) , |
54 | pnttg2sol(1,8) , |
55 | pnttg3sol(1,8) , |
56 | par1sol(1,8) , |
57 | par2sol(1,8) , |
58 | par3sol(1,8) , |
59 | pararg1(1,8) , |
60 | pararg2(1,8) , |
61 | pararg3(1,8) |
62 | { |
63 | |
64 | TheSame1.Init(0); |
65 | |
66 | gp_Dir2d dirx(1.0,0.0); |
67 | Standard_Real Tol = Abs(Tolerance); |
68 | WellDone = Standard_False; |
69 | NbrSol = 0; |
70 | if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || |
71 | Qualified1.IsOutside() || Qualified1.IsUnqualified()) || |
72 | !(Qualified2.IsEnclosed() || |
73 | Qualified2.IsOutside() || Qualified2.IsUnqualified()) || |
74 | !(Qualified3.IsEnclosed() || |
75 | Qualified3.IsOutside() || Qualified3.IsUnqualified())) { |
9775fa61 |
76 | throw GccEnt_BadQualifier(); |
7fd59977 |
77 | return; |
78 | } |
79 | |
80 | //========================================================================= |
0d969553 |
81 | // Processing. + |
7fd59977 |
82 | //========================================================================= |
83 | |
84 | gp_Circ2d C1 = Qualified1.Qualified(); |
85 | gp_Lin2d L2 = Qualified2.Qualified(); |
86 | gp_Lin2d L3 = Qualified3.Qualified(); |
87 | Standard_Real R1 = C1.Radius(); |
88 | gp_Pnt2d center1(C1.Location()); |
89 | gp_Pnt2d origin2(L2.Location()); |
90 | gp_Dir2d dir2(L2.Direction()); |
91 | gp_Dir2d normL2(-dir2.Y(),dir2.X()); |
92 | gp_Pnt2d origin3(L3.Location()); |
93 | gp_Dir2d dir3(L3.Direction()); |
94 | gp_Dir2d normL3(-dir3.Y(),dir3.X()); |
95 | |
96 | TColStd_Array1OfReal Radius(1,2); |
97 | GccAna_CircLin2dBisec Bis1(C1,L2); |
98 | GccAna_Lin2dBisec Bis2(L2,L3); |
99 | if (Bis1.IsDone() && Bis2.IsDone()) { |
100 | Standard_Integer nbsolution1 = Bis1.NbSolutions(); |
101 | Standard_Integer nbsolution2 = Bis2.NbSolutions(); |
102 | for (Standard_Integer i = 1 ; i <= nbsolution1; i++) { |
103 | Handle(GccInt_Bisec) Sol1 = Bis1.ThisSolution(i); |
104 | GccInt_IType typ1 = Sol1->ArcType(); |
105 | IntAna2d_AnaIntersection Intp; |
106 | for (Standard_Integer k = 1 ; k <= nbsolution2; k++) { |
107 | if (typ1 == GccInt_Lin) { |
108 | Intp.Perform(Sol1->Line(),Bis2.ThisSolution(k)); |
109 | } |
110 | else if (typ1 == GccInt_Par) { |
111 | Intp.Perform(Bis2.ThisSolution(k),IntAna2d_Conic(Sol1->Parabola())); |
112 | } |
113 | if (Intp.IsDone()) { |
114 | if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&& |
115 | (!Intp.IdenticalElements())) { |
116 | for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) { |
117 | gp_Pnt2d Center(Intp.Point(j).Value()); |
118 | Standard_Real dist1 = Center.Distance(center1); |
119 | Standard_Real dist2 = L2.Distance(Center); |
120 | Standard_Real dist3 = L3.Distance(Center); |
121 | Standard_Integer nbsol1 = 0; |
7fd59977 |
122 | Standard_Integer nbsol3 = 0; |
123 | Standard_Boolean ok = Standard_False; |
124 | if (Qualified1.IsEnclosed()) { |
125 | if (dist1-R1 < Tolerance) { |
126 | Radius(1) = Abs(R1-dist1); |
127 | nbsol1 = 1; |
128 | ok = Standard_True; |
129 | } |
130 | } |
131 | else if (Qualified1.IsOutside()) { |
132 | if (R1-dist1 < Tolerance) { |
133 | Radius(1) = Abs(R1-dist1); |
134 | nbsol1 = 1; |
135 | ok = Standard_True; |
136 | } |
137 | } |
138 | else if (Qualified1.IsEnclosing()) { |
139 | ok = Standard_True; |
140 | nbsol1 = 1; |
141 | Radius(1) = Abs(R1-dist1); |
142 | } |
143 | else if (Qualified1.IsUnqualified()) { |
144 | ok = Standard_True; |
145 | nbsol1 = 2; |
146 | Radius(1) = Abs(R1-dist1); |
147 | Radius(2) = R1+dist1; |
148 | } |
149 | if (Qualified2.IsEnclosed() && ok) { |
150 | if ((((origin2.X()-Center.X())*(-dir2.Y()))+ |
151 | ((origin2.Y()-Center.Y())*(dir2.X())))<=0){ |
152 | for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) { |
153 | if (Abs(dist2-Radius(ii)) < Tol) { |
154 | ok = Standard_True; |
7fd59977 |
155 | Radius(1) = Radius(ii); |
156 | } |
157 | } |
158 | } |
159 | } |
160 | else if (Qualified2.IsOutside() && ok) { |
161 | if ((((origin2.X()-Center.X())*(-dir2.Y()))+ |
162 | ((origin2.Y()-Center.Y())*(dir2.X())))>=0){ |
163 | for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) { |
164 | if (Abs(dist2-Radius(ii)) < Tol) { |
165 | ok = Standard_True; |
7fd59977 |
166 | Radius(1) = Radius(ii); |
167 | } |
168 | } |
169 | } |
170 | } |
171 | else if (Qualified2.IsUnqualified() && ok) { |
172 | for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) { |
173 | if (Abs(dist2-Radius(ii)) < Tol) { |
174 | ok = Standard_True; |
7fd59977 |
175 | Radius(1) = Radius(ii); |
176 | } |
177 | } |
178 | } |
179 | if (Qualified3.IsEnclosed() && ok) { |
180 | if ((((origin3.X()-Center.X())*(-dir3.Y()))+ |
181 | ((origin3.Y()-Center.Y())*(dir3.X())))<=0){ |
182 | if (Abs(dist3-Radius(1)) < Tol) { |
183 | ok = Standard_True; |
184 | nbsol3 = 1; |
185 | } |
186 | } |
187 | } |
188 | else if (Qualified3.IsOutside() && ok) { |
189 | if ((((origin3.X()-Center.X())*(-dir3.Y()))+ |
190 | ((origin3.Y()-Center.Y())*(dir3.X())))>=0){ |
191 | if (Abs(dist3-Radius(1)) < Tol) { |
192 | ok = Standard_True; |
193 | nbsol3 = 1; |
194 | } |
195 | } |
196 | } |
197 | else if (Qualified3.IsUnqualified() && ok) { |
198 | if (Abs(dist3-Radius(1)) < Tol) { |
199 | ok = Standard_True; |
200 | nbsol3 = 1; |
201 | } |
202 | } |
203 | if (ok) { |
3d8539a3 |
204 | for (Standard_Integer m = 1 ; m <= nbsol3 ; m++) { |
7fd59977 |
205 | NbrSol++; |
3d8539a3 |
206 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(m)); |
7fd59977 |
207 | // ========================================================== |
208 | Standard_Real distcc1 = Center.Distance(center1); |
209 | if (!Qualified1.IsUnqualified()) { |
210 | qualifier1(NbrSol) = Qualified1.Qualifier(); |
211 | } |
3d8539a3 |
212 | else if (Abs(distcc1+Radius(m)-R1) < Tol) { |
7fd59977 |
213 | qualifier1(NbrSol) = GccEnt_enclosed; |
214 | } |
3d8539a3 |
215 | else if (Abs(distcc1-R1-Radius(m)) < Tol) { |
7fd59977 |
216 | qualifier1(NbrSol) = GccEnt_outside; |
217 | } |
218 | else { qualifier1(NbrSol) = GccEnt_enclosing; } |
219 | gp_Dir2d dc2(origin2.XY()-Center.XY()); |
220 | if (!Qualified2.IsUnqualified()) { |
221 | qualifier2(NbrSol) = Qualified2.Qualifier(); |
222 | } |
223 | else if (dc2.Dot(normL2) > 0.0) { |
224 | qualifier2(NbrSol) = GccEnt_outside; |
225 | } |
226 | else { qualifier2(NbrSol) = GccEnt_enclosed; } |
227 | gp_Dir2d dc3(origin3.XY()-Center.XY()); |
228 | if (!Qualified3.IsUnqualified()) { |
229 | qualifier3(NbrSol) = Qualified3.Qualifier(); |
230 | } |
231 | else if (dc3.Dot(normL3) > 0.0) { |
232 | qualifier3(NbrSol) = GccEnt_outside; |
233 | } |
234 | else { qualifier3(NbrSol) = GccEnt_enclosed; } |
235 | if (Center.Distance(center1) <= Tolerance && |
3d8539a3 |
236 | Abs(Radius(m)-R1) <= Tolerance) { |
7fd59977 |
237 | TheSame1(NbrSol) = 1; |
238 | } |
239 | else { |
240 | TheSame1(NbrSol) = 0; |
241 | gp_Dir2d dc(center1.XY()-Center.XY()); |
3d8539a3 |
242 | pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(m)*dc.XY()); |
7fd59977 |
243 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
244 | pnttg1sol(NbrSol)); |
245 | pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol)); |
246 | } |
247 | TheSame2(NbrSol) = 0; |
248 | TheSame3(NbrSol) = 0; |
249 | gp_Dir2d dc(origin2.XY()-Center.XY()); |
250 | Standard_Real sign = dc.Dot(gp_Dir2d(-dir2.Y(),dir2.X())); |
251 | dc = gp_Dir2d(sign*gp_XY(-dir2.Y(),dir2.X())); |
3d8539a3 |
252 | pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius(m)*dc.XY()); |
7fd59977 |
253 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
254 | pnttg2sol(NbrSol)); |
255 | pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol)); |
256 | dc = gp_Dir2d(origin3.XY()-Center.XY()); |
257 | sign = dc.Dot(gp_Dir2d(-dir3.Y(),dir3.X())); |
258 | dc = gp_Dir2d(sign*gp_XY(-dir3.Y(),dir3.X())); |
3d8539a3 |
259 | pnttg3sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius(m)*dc.XY()); |
7fd59977 |
260 | par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
261 | pnttg3sol(NbrSol)); |
262 | pararg3(NbrSol)=ElCLib::Parameter(L3,pnttg3sol(NbrSol)); |
263 | } |
264 | } |
265 | } |
266 | } |
267 | WellDone = Standard_True; |
268 | } |
269 | } |
270 | } |
271 | } |
272 | } |
273 | |
274 | |