Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1992-01-02 |
2 | // Created by: Remi GILET | |
3 | // Copyright (c) 1992-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
7fd59977 | 17 | |
18 | #include <ElCLib.hxx> | |
42cf5bc1 | 19 | #include <GccAna_Circ2d2TanOn.hxx> |
7fd59977 | 20 | #include <GccAna_Circ2dBisec.hxx> |
42cf5bc1 | 21 | #include <GccEnt_BadQualifier.hxx> |
22 | #include <GccEnt_QualifiedCirc.hxx> | |
23 | #include <GccEnt_QualifiedLin.hxx> | |
7fd59977 | 24 | #include <GccInt_BCirc.hxx> |
25 | #include <GccInt_BLine.hxx> | |
42cf5bc1 | 26 | #include <GccInt_IType.hxx> |
27 | #include <gp_Ax2d.hxx> | |
28 | #include <gp_Circ2d.hxx> | |
29 | #include <gp_Dir2d.hxx> | |
30 | #include <gp_Lin2d.hxx> | |
31 | #include <gp_Pnt2d.hxx> | |
32 | #include <IntAna2d_AnaIntersection.hxx> | |
7fd59977 | 33 | #include <IntAna2d_Conic.hxx> |
42cf5bc1 | 34 | #include <IntAna2d_IntPoint.hxx> |
35 | #include <Standard_OutOfRange.hxx> | |
36 | #include <StdFail_NotDone.hxx> | |
7fd59977 | 37 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 | 38 | |
39 | //========================================================================= | |
0d969553 Y |
40 | // Creation of a circle tangent to two circles C1 and C2. + |
41 | // centered on a circle. + | |
42 | // We start with distinguishing various boundary cases that will be + | |
43 | // processed separately. + | |
44 | // In the general case: + | |
7fd59977 | 45 | // ==================== + |
0d969553 Y |
46 | // We calculate bissectrices to C1 and C2 that give us all + |
47 | // possible locations of centers of all circles tangent to C1 and C2. + | |
48 | // We intersect these bissectrices with circle OnCirc which gives us + | |
49 | // points among which we choose the solutions. + | |
50 | // The choice is made basing in Qualifiers of C1 and C2. + | |
7fd59977 | 51 | //========================================================================= |
7fd59977 | 52 | GccAna_Circ2d2TanOn:: |
53 | GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 , | |
54 | const GccEnt_QualifiedCirc& Qualified2 , | |
55 | const gp_Circ2d& OnCirc , | |
56 | const Standard_Real Tolerance ): | |
57 | cirsol(1,8) , | |
58 | qualifier1(1,8) , | |
59 | qualifier2(1,8) , | |
60 | TheSame1(1,8) , | |
61 | TheSame2(1,8) , | |
62 | pnttg1sol(1,8) , | |
63 | pnttg2sol(1,8) , | |
64 | pntcen(1,8) , | |
65 | par1sol(1,8) , | |
66 | par2sol(1,8) , | |
67 | pararg1(1,8) , | |
68 | pararg2(1,8) , | |
69 | parcen3(1,8) | |
70 | { | |
71 | TheSame1.Init(0); | |
72 | TheSame2.Init(0); | |
73 | WellDone = Standard_False; | |
74 | NbrSol = 0; | |
75 | if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || | |
76 | Qualified1.IsOutside() || Qualified1.IsUnqualified()) || | |
77 | !(Qualified2.IsEnclosed() || Qualified2.IsEnclosing() || | |
78 | Qualified2.IsOutside() || Qualified2.IsUnqualified())) { | |
9775fa61 | 79 | throw GccEnt_BadQualifier(); |
7fd59977 | 80 | return; |
81 | } | |
82 | Standard_Real Tol= Abs(Tolerance); | |
83 | gp_Circ2d C1 = Qualified1.Qualified(); | |
84 | gp_Circ2d C2 = Qualified2.Qualified(); | |
85 | gp_Dir2d dirx(1.,0.); | |
86 | TColStd_Array1OfReal Radius(1,2); | |
87 | TColStd_Array1OfReal Rradius(1,2); | |
88 | gp_Pnt2d center1(C1.Location()); | |
89 | gp_Pnt2d center2(C2.Location()); | |
6e6cd5d9 | 90 | |
7fd59977 | 91 | Standard_Real R1 = C1.Radius(); |
92 | Standard_Real R2 = C2.Radius(); | |
93 | ||
94 | //========================================================================= | |
0d969553 | 95 | // Processing of boundary cases. + |
7fd59977 | 96 | //========================================================================= |
97 | ||
98 | Standard_Integer nbsol1 = 1; | |
99 | Standard_Integer nbsol2 = 0; | |
100 | Standard_Real Ron = OnCirc.Radius(); | |
101 | Standard_Real distcco = OnCirc.Location().Distance(center1); | |
102 | gp_Dir2d dircc(OnCirc.Location().XY()-center1.XY()); | |
103 | gp_Pnt2d pinterm(center1.XY()+(distcco-Ron)*dircc.XY()); | |
104 | Standard_Real distcc2 =pinterm.Distance(center2); | |
105 | Standard_Real distcc1 =pinterm.Distance(center1); | |
106 | Standard_Real d1 = Abs(distcc2-R2-Abs(distcc1-R1)); | |
107 | Standard_Real d2 = Abs(distcc2+R2-Abs(distcc1-R1)); | |
108 | Standard_Real d3 = Abs(distcc2-R2-(distcc1+R1)); | |
109 | Standard_Real d4 = Abs(distcc2+R2-(distcc1+R1)); | |
110 | if ( d1 > Tol || d2 > Tol || d3 > Tol || d4 > Tol) { | |
111 | pinterm = gp_Pnt2d(center1.XY()+(distcco+Ron)*dircc.XY()); | |
112 | distcc2 =pinterm.Distance(center2); | |
113 | distcc1 =pinterm.Distance(center1); | |
114 | d1 = Abs(distcc2-R2-Abs(distcc1-R1)); | |
115 | d2 = Abs(distcc2+R2-Abs(distcc1-R1)); | |
116 | d3 = Abs(distcc2-R2-(distcc1+R1)); | |
117 | d4 = Abs(distcc2+R2-(distcc1+R1)); | |
118 | if ( d1 > Tol || d2 > Tol || d3 > Tol || d4 > Tol) { nbsol1 = 0; } | |
119 | } | |
120 | if (nbsol1 > 0) { | |
121 | if (Qualified1.IsEnclosed() || Qualified1.IsOutside()) { | |
122 | nbsol1 = 1; | |
123 | Radius(1) = Abs(distcc1-R1); | |
124 | } | |
125 | else if (Qualified1.IsEnclosing()) { | |
126 | nbsol1 = 1; | |
127 | Radius(1) = R1+distcc1; | |
128 | } | |
129 | else if (Qualified1.IsUnqualified()) { | |
130 | nbsol1 = 2; | |
131 | Radius(1) = Abs(distcc1-R1); | |
132 | Radius(2) = R1+distcc1; | |
133 | } | |
134 | if (Qualified2.IsEnclosed() || Qualified2.IsOutside()) { | |
135 | nbsol2 = 1; | |
136 | Rradius(1) = Abs(distcc2-R2); | |
137 | } | |
138 | else if (Qualified2.IsEnclosing()) { | |
139 | nbsol2 = 1; | |
140 | Rradius(1) = R2+distcc2; | |
141 | } | |
142 | else if (Qualified2.IsUnqualified()) { | |
143 | nbsol2 = 2; | |
144 | Rradius(1) = Abs(distcc2-R2); | |
145 | Rradius(2) = R2+distcc2; | |
146 | } | |
147 | for (Standard_Integer i = 1 ; i <= nbsol1 ; i++) { | |
148 | for (Standard_Integer j = 1 ; j <= nbsol2 ; j++) { | |
149 | if (Abs(Radius(i)-Rradius(j)) <= Tol) { | |
150 | WellDone = Standard_True; | |
151 | NbrSol++; | |
152 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),Radius(i)); | |
153 | // =========================================================== | |
154 | gp_Dir2d dc1(center1.XY()-pinterm.XY()); | |
155 | gp_Dir2d dc2(center2.XY()-pinterm.XY()); | |
156 | distcc1 = pinterm.Distance(center1); | |
157 | distcc2 = pinterm.Distance(center2); | |
158 | if (!Qualified1.IsUnqualified()) { | |
159 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
160 | } | |
161 | else if (Abs(distcc1+Radius(i)-R1) < Tol) { | |
162 | qualifier1(NbrSol) = GccEnt_enclosed; | |
163 | } | |
164 | else if (Abs(distcc1-R1-Radius(i)) < Tol) { | |
165 | qualifier1(NbrSol) = GccEnt_outside; | |
166 | } | |
167 | else { qualifier1(NbrSol) = GccEnt_enclosing; } | |
168 | if (!Qualified2.IsUnqualified()) { | |
169 | qualifier2(NbrSol) = Qualified2.Qualifier(); | |
170 | } | |
171 | else if (Abs(distcc2+Radius(i)-R2) < Tol) { | |
172 | qualifier2(NbrSol) = GccEnt_enclosed; | |
173 | } | |
174 | else if (Abs(distcc2-R2-Radius(i)) < Tol) { | |
175 | qualifier2(NbrSol) = GccEnt_outside; | |
176 | } | |
177 | else { qualifier2(NbrSol) = GccEnt_enclosing; } | |
178 | pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+Radius(i)*dc1.XY()); | |
179 | pnttg2sol(NbrSol) = gp_Pnt2d(pinterm.XY()+Radius(i)*dc2.XY()); | |
180 | pntcen(NbrSol) = cirsol(NbrSol).Location(); | |
181 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol)); | |
182 | pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol)); | |
183 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol)); | |
184 | pararg2(NbrSol)=ElCLib::Parameter(C2,pnttg2sol(NbrSol)); | |
185 | parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol)); | |
186 | } | |
187 | } | |
188 | } | |
189 | if (WellDone) { return; } | |
190 | } | |
191 | ||
192 | //========================================================================= | |
0d969553 | 193 | // General case. + |
7fd59977 | 194 | //========================================================================= |
195 | ||
196 | GccAna_Circ2dBisec Bis(C1,C2); | |
197 | if (Bis.IsDone()) { | |
198 | TColStd_Array1OfReal Rbid(1,2); | |
199 | TColStd_Array1OfReal RBid(1,2); | |
200 | Standard_Integer nbsolution = Bis.NbSolutions(); | |
201 | for (Standard_Integer i = 1 ; i <= nbsolution ; i++) { | |
202 | Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i); | |
203 | GccInt_IType typ = Sol->ArcType(); | |
204 | IntAna2d_AnaIntersection Intp; | |
205 | if (typ == GccInt_Cir) { | |
206 | Intp.Perform(OnCirc,Sol->Circle()); | |
207 | } | |
208 | else if (typ == GccInt_Lin) { | |
209 | Intp.Perform(Sol->Line(),OnCirc); | |
210 | } | |
211 | else if (typ == GccInt_Hpr) { | |
212 | Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Hyperbola())); | |
213 | } | |
214 | else if (typ == GccInt_Ell) { | |
215 | Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Ellipse())); | |
216 | } | |
217 | if (Intp.IsDone()) { | |
218 | if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&& | |
219 | (!Intp.IdenticalElements())) { | |
220 | for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) { | |
221 | gp_Pnt2d Center(Intp.Point(j).Value()); | |
222 | Standard_Real dist1 = Center.Distance(center1); | |
223 | Standard_Real dist2 = Center.Distance(center2); | |
224 | Standard_Integer nbsol = 0; | |
225 | Standard_Integer nsol = 0; | |
226 | Standard_Integer nnsol = 0; | |
227 | R1 = C1.Radius(); | |
228 | R2 = C2.Radius(); | |
229 | if (Qualified1.IsEnclosed()) { | |
230 | if (dist1-R1 < Tol) { | |
231 | nbsol = 1; | |
232 | Rbid(1) = Abs(R1-dist1); | |
233 | } | |
234 | } | |
235 | else if (Qualified1.IsOutside()) { | |
236 | if (R1-dist1 < Tol) { | |
237 | nbsol = 1; | |
238 | Rbid(1) = Abs(dist1-R1); | |
239 | } | |
240 | } | |
241 | else if (Qualified1.IsEnclosing()) { | |
242 | nbsol = 1; | |
243 | Rbid(1) = dist1+R1; | |
244 | } | |
245 | else if (Qualified1.IsUnqualified()) { | |
246 | nbsol = 2; | |
247 | Rbid(1) = dist1+R1; | |
248 | Rbid(1) = Abs(dist1-R1); | |
249 | } | |
250 | if (Qualified2.IsEnclosed() && nbsol != 0) { | |
251 | if (dist2-R2 < Tol) { | |
252 | nsol = 1; | |
253 | RBid(1) = Abs(R2-dist2); | |
254 | } | |
255 | } | |
256 | else if (Qualified2.IsOutside() && nbsol != 0) { | |
257 | if (R2-dist2 < Tol) { | |
258 | nsol = 1; | |
259 | RBid(1) = Abs(R2-dist2); | |
260 | } | |
261 | } | |
262 | else if (Qualified2.IsEnclosing() && nbsol != 0) { | |
263 | nsol = 1; | |
264 | RBid(1) = dist2+R2; | |
265 | } | |
266 | else if (Qualified2.IsUnqualified() && nbsol != 0) { | |
267 | nsol = 2; | |
268 | RBid(1) = dist2+R2; | |
269 | RBid(2) = Abs(R2-dist2); | |
270 | } | |
271 | for (Standard_Integer isol = 1; isol <= nbsol ; isol++) { | |
272 | for (Standard_Integer jsol = 1; jsol <= nsol ; jsol++) { | |
273 | if (Abs(Rbid(isol)-RBid(jsol)) <= Tol) { | |
274 | nnsol++; | |
275 | Radius(nnsol) = (RBid(jsol)+Rbid(isol))/2.; | |
276 | } | |
277 | } | |
278 | } | |
279 | if (nnsol > 0) { | |
280 | for (Standard_Integer k = 1 ; k <= nnsol ; k++) { | |
281 | NbrSol++; | |
282 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k)); | |
283 | // ========================================================== | |
284 | distcc1 = Center.Distance(center1); | |
285 | distcc2 = Center.Distance(center2); | |
286 | if (!Qualified1.IsUnqualified()) { | |
287 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
288 | } | |
289 | else if (Abs(distcc1+Radius(k)-R1) < Tol) { | |
290 | qualifier1(NbrSol) = GccEnt_enclosed; | |
291 | } | |
292 | else if (Abs(distcc1-R1-Radius(k)) < Tol) { | |
293 | qualifier1(NbrSol) = GccEnt_outside; | |
294 | } | |
295 | else { qualifier1(NbrSol) = GccEnt_enclosing; } | |
296 | if (!Qualified2.IsUnqualified()) { | |
297 | qualifier2(NbrSol) = Qualified2.Qualifier(); | |
298 | } | |
299 | else if (Abs(distcc2+Radius(k)-R2) < Tol) { | |
300 | qualifier2(NbrSol) = GccEnt_enclosed; | |
301 | } | |
302 | else if (Abs(distcc2-R2-Radius(k)) < Tol) { | |
303 | qualifier2(NbrSol) = GccEnt_outside; | |
304 | } | |
305 | else { qualifier2(NbrSol) = GccEnt_enclosing; } | |
306 | if (Center.Distance(center1) <= Tolerance && | |
307 | Abs(Radius(k)-C1.Radius()) <= Tolerance) { | |
308 | TheSame1(NbrSol) = 1; | |
309 | } | |
310 | else { | |
311 | TheSame1(NbrSol) = 0; | |
312 | gp_Dir2d dc1(center1.XY()-Center.XY()); | |
313 | pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(k)*dc1.XY()); | |
314 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
315 | pnttg1sol(NbrSol)); | |
316 | pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol)); | |
317 | } | |
318 | if (Center.Distance(center2) <= Tolerance && | |
319 | Abs(Radius(k)-C2.Radius()) <= Tolerance) { | |
320 | TheSame2(NbrSol) = 1; | |
321 | } | |
322 | else { | |
323 | TheSame2(NbrSol) = 0; | |
324 | gp_Dir2d dc2(center2.XY()-Center.XY()); | |
325 | pnttg2sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(k)*dc2.XY()); | |
326 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
327 | pnttg2sol(NbrSol)); | |
328 | pararg2(NbrSol)=ElCLib::Parameter(C2,pnttg2sol(NbrSol)); | |
329 | } | |
330 | pntcen(NbrSol) = Center; | |
331 | parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol)); | |
332 | } | |
333 | } | |
334 | } | |
335 | } | |
336 | WellDone = Standard_True; | |
337 | } | |
338 | } | |
339 | } | |
340 | } | |
341 |