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