Integration of OCCT 6.5.0 from SVN
[occt.git] / src / GccAna / GccAna_Circ2d2TanOn_6.cxx
CommitLineData
7fd59977 1// File: GccAna_Circ2d2TanOn_6.cxx
2// Created: Thu Jan 2 15:56:04 1992
3// Author: Remi GILET
4// <reg@topsn3>
5
6#include <GccAna_Circ2d2TanOn.jxx>
7
8#include <ElCLib.hxx>
9#include <gp_Dir2d.hxx>
10#include <gp_Ax2d.hxx>
11#include <IntAna2d_AnaIntersection.hxx>
12#include <IntAna2d_IntPoint.hxx>
13#include <GccAna_Circ2dBisec.hxx>
14#include <GccInt_IType.hxx>
15#include <GccInt_BCirc.hxx>
16#include <GccInt_BLine.hxx>
17#include <IntAna2d_Conic.hxx>
18#include <TColStd_Array1OfReal.hxx>
19#include <GccEnt_BadQualifier.hxx>
20
21//=========================================================================
22// Creation d un cercle tangent a deux cercle C1 et C2. +
23// centre sur un cercle. +
24// Nous commencons par distinguer les differents cas limites que nous +
25// allons traiter separement. +
26// Pour le cas general: +
27// ==================== +
28// Nous calculons les bissectrices a C1 et C2 qui nous donnent +
29// l ensemble des lieux possibles des centres de tous les cercles +
30// tangents aC1 et C2. +
31// Nous intersectons ces bissectrices avec le cercle OnCirc ce qui nous +
32// donne les points parmis lesquels nous allons choisir les solutions. +
33// Les choix s effectuent a partir des Qualifieurs qualifiant C1 et C2. +
34//=========================================================================
35
36GccAna_Circ2d2TanOn::
37 GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 ,
38 const GccEnt_QualifiedCirc& Qualified2 ,
39 const gp_Circ2d& OnCirc ,
40 const Standard_Real Tolerance ):
41 cirsol(1,8) ,
42 qualifier1(1,8) ,
43 qualifier2(1,8) ,
44 TheSame1(1,8) ,
45 TheSame2(1,8) ,
46 pnttg1sol(1,8) ,
47 pnttg2sol(1,8) ,
48 pntcen(1,8) ,
49 par1sol(1,8) ,
50 par2sol(1,8) ,
51 pararg1(1,8) ,
52 pararg2(1,8) ,
53 parcen3(1,8)
54{
55 TheSame1.Init(0);
56 TheSame2.Init(0);
57 WellDone = Standard_False;
58 NbrSol = 0;
59 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
60 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
61 !(Qualified2.IsEnclosed() || Qualified2.IsEnclosing() ||
62 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
63 GccEnt_BadQualifier::Raise();
64 return;
65 }
66 Standard_Real Tol= Abs(Tolerance);
67 gp_Circ2d C1 = Qualified1.Qualified();
68 gp_Circ2d C2 = Qualified2.Qualified();
69 gp_Dir2d dirx(1.,0.);
70 TColStd_Array1OfReal Radius(1,2);
71 TColStd_Array1OfReal Rradius(1,2);
72 gp_Pnt2d center1(C1.Location());
73 gp_Pnt2d center2(C2.Location());
74#ifdef DEB
75 Standard_Real distance = center1.Distance(center2);
76#else
77 center1.Distance(center2);
78#endif
79 Standard_Real R1 = C1.Radius();
80 Standard_Real R2 = C2.Radius();
81
82//=========================================================================
83// Traitement des cas limites. +
84//=========================================================================
85
86 Standard_Integer nbsol1 = 1;
87 Standard_Integer nbsol2 = 0;
88 Standard_Real Ron = OnCirc.Radius();
89 Standard_Real distcco = OnCirc.Location().Distance(center1);
90 gp_Dir2d dircc(OnCirc.Location().XY()-center1.XY());
91 gp_Pnt2d pinterm(center1.XY()+(distcco-Ron)*dircc.XY());
92 Standard_Real distcc2 =pinterm.Distance(center2);
93 Standard_Real distcc1 =pinterm.Distance(center1);
94 Standard_Real d1 = Abs(distcc2-R2-Abs(distcc1-R1));
95 Standard_Real d2 = Abs(distcc2+R2-Abs(distcc1-R1));
96 Standard_Real d3 = Abs(distcc2-R2-(distcc1+R1));
97 Standard_Real d4 = Abs(distcc2+R2-(distcc1+R1));
98 if ( d1 > Tol || d2 > Tol || d3 > Tol || d4 > Tol) {
99 pinterm = gp_Pnt2d(center1.XY()+(distcco+Ron)*dircc.XY());
100 distcc2 =pinterm.Distance(center2);
101 distcc1 =pinterm.Distance(center1);
102 d1 = Abs(distcc2-R2-Abs(distcc1-R1));
103 d2 = Abs(distcc2+R2-Abs(distcc1-R1));
104 d3 = Abs(distcc2-R2-(distcc1+R1));
105 d4 = Abs(distcc2+R2-(distcc1+R1));
106 if ( d1 > Tol || d2 > Tol || d3 > Tol || d4 > Tol) { nbsol1 = 0; }
107 }
108 if (nbsol1 > 0) {
109 if (Qualified1.IsEnclosed() || Qualified1.IsOutside()) {
110 nbsol1 = 1;
111 Radius(1) = Abs(distcc1-R1);
112 }
113 else if (Qualified1.IsEnclosing()) {
114 nbsol1 = 1;
115 Radius(1) = R1+distcc1;
116 }
117 else if (Qualified1.IsUnqualified()) {
118 nbsol1 = 2;
119 Radius(1) = Abs(distcc1-R1);
120 Radius(2) = R1+distcc1;
121 }
122 if (Qualified2.IsEnclosed() || Qualified2.IsOutside()) {
123 nbsol2 = 1;
124 Rradius(1) = Abs(distcc2-R2);
125 }
126 else if (Qualified2.IsEnclosing()) {
127 nbsol2 = 1;
128 Rradius(1) = R2+distcc2;
129 }
130 else if (Qualified2.IsUnqualified()) {
131 nbsol2 = 2;
132 Rradius(1) = Abs(distcc2-R2);
133 Rradius(2) = R2+distcc2;
134 }
135 for (Standard_Integer i = 1 ; i <= nbsol1 ; i++) {
136 for (Standard_Integer j = 1 ; j <= nbsol2 ; j++) {
137 if (Abs(Radius(i)-Rradius(j)) <= Tol) {
138 WellDone = Standard_True;
139 NbrSol++;
140 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),Radius(i));
141// ===========================================================
142 gp_Dir2d dc1(center1.XY()-pinterm.XY());
143 gp_Dir2d dc2(center2.XY()-pinterm.XY());
144 distcc1 = pinterm.Distance(center1);
145 distcc2 = pinterm.Distance(center2);
146 if (!Qualified1.IsUnqualified()) {
147 qualifier1(NbrSol) = Qualified1.Qualifier();
148 }
149 else if (Abs(distcc1+Radius(i)-R1) < Tol) {
150 qualifier1(NbrSol) = GccEnt_enclosed;
151 }
152 else if (Abs(distcc1-R1-Radius(i)) < Tol) {
153 qualifier1(NbrSol) = GccEnt_outside;
154 }
155 else { qualifier1(NbrSol) = GccEnt_enclosing; }
156 if (!Qualified2.IsUnqualified()) {
157 qualifier2(NbrSol) = Qualified2.Qualifier();
158 }
159 else if (Abs(distcc2+Radius(i)-R2) < Tol) {
160 qualifier2(NbrSol) = GccEnt_enclosed;
161 }
162 else if (Abs(distcc2-R2-Radius(i)) < Tol) {
163 qualifier2(NbrSol) = GccEnt_outside;
164 }
165 else { qualifier2(NbrSol) = GccEnt_enclosing; }
166 pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+Radius(i)*dc1.XY());
167 pnttg2sol(NbrSol) = gp_Pnt2d(pinterm.XY()+Radius(i)*dc2.XY());
168 pntcen(NbrSol) = cirsol(NbrSol).Location();
169 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
170 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
171 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
172 pararg2(NbrSol)=ElCLib::Parameter(C2,pnttg2sol(NbrSol));
173 parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol));
174 }
175 }
176 }
177 if (WellDone) { return; }
178 }
179
180//=========================================================================
181// Cas general. +
182//=========================================================================
183
184 GccAna_Circ2dBisec Bis(C1,C2);
185 if (Bis.IsDone()) {
186 TColStd_Array1OfReal Rbid(1,2);
187 TColStd_Array1OfReal RBid(1,2);
188 Standard_Integer nbsolution = Bis.NbSolutions();
189 for (Standard_Integer i = 1 ; i <= nbsolution ; i++) {
190 Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i);
191 GccInt_IType typ = Sol->ArcType();
192 IntAna2d_AnaIntersection Intp;
193 if (typ == GccInt_Cir) {
194 Intp.Perform(OnCirc,Sol->Circle());
195 }
196 else if (typ == GccInt_Lin) {
197 Intp.Perform(Sol->Line(),OnCirc);
198 }
199 else if (typ == GccInt_Hpr) {
200 Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Hyperbola()));
201 }
202 else if (typ == GccInt_Ell) {
203 Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Ellipse()));
204 }
205 if (Intp.IsDone()) {
206 if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
207 (!Intp.IdenticalElements())) {
208 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
209 gp_Pnt2d Center(Intp.Point(j).Value());
210 Standard_Real dist1 = Center.Distance(center1);
211 Standard_Real dist2 = Center.Distance(center2);
212 Standard_Integer nbsol = 0;
213 Standard_Integer nsol = 0;
214 Standard_Integer nnsol = 0;
215 R1 = C1.Radius();
216 R2 = C2.Radius();
217 if (Qualified1.IsEnclosed()) {
218 if (dist1-R1 < Tol) {
219 nbsol = 1;
220 Rbid(1) = Abs(R1-dist1);
221 }
222 }
223 else if (Qualified1.IsOutside()) {
224 if (R1-dist1 < Tol) {
225 nbsol = 1;
226 Rbid(1) = Abs(dist1-R1);
227 }
228 }
229 else if (Qualified1.IsEnclosing()) {
230 nbsol = 1;
231 Rbid(1) = dist1+R1;
232 }
233 else if (Qualified1.IsUnqualified()) {
234 nbsol = 2;
235 Rbid(1) = dist1+R1;
236 Rbid(1) = Abs(dist1-R1);
237 }
238 if (Qualified2.IsEnclosed() && nbsol != 0) {
239 if (dist2-R2 < Tol) {
240 nsol = 1;
241 RBid(1) = Abs(R2-dist2);
242 }
243 }
244 else if (Qualified2.IsOutside() && nbsol != 0) {
245 if (R2-dist2 < Tol) {
246 nsol = 1;
247 RBid(1) = Abs(R2-dist2);
248 }
249 }
250 else if (Qualified2.IsEnclosing() && nbsol != 0) {
251 nsol = 1;
252 RBid(1) = dist2+R2;
253 }
254 else if (Qualified2.IsUnqualified() && nbsol != 0) {
255 nsol = 2;
256 RBid(1) = dist2+R2;
257 RBid(2) = Abs(R2-dist2);
258 }
259 for (Standard_Integer isol = 1; isol <= nbsol ; isol++) {
260 for (Standard_Integer jsol = 1; jsol <= nsol ; jsol++) {
261 if (Abs(Rbid(isol)-RBid(jsol)) <= Tol) {
262 nnsol++;
263 Radius(nnsol) = (RBid(jsol)+Rbid(isol))/2.;
264 }
265 }
266 }
267 if (nnsol > 0) {
268 for (Standard_Integer k = 1 ; k <= nnsol ; k++) {
269 NbrSol++;
270 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
271// ==========================================================
272 distcc1 = Center.Distance(center1);
273 distcc2 = Center.Distance(center2);
274 if (!Qualified1.IsUnqualified()) {
275 qualifier1(NbrSol) = Qualified1.Qualifier();
276 }
277 else if (Abs(distcc1+Radius(k)-R1) < Tol) {
278 qualifier1(NbrSol) = GccEnt_enclosed;
279 }
280 else if (Abs(distcc1-R1-Radius(k)) < Tol) {
281 qualifier1(NbrSol) = GccEnt_outside;
282 }
283 else { qualifier1(NbrSol) = GccEnt_enclosing; }
284 if (!Qualified2.IsUnqualified()) {
285 qualifier2(NbrSol) = Qualified2.Qualifier();
286 }
287 else if (Abs(distcc2+Radius(k)-R2) < Tol) {
288 qualifier2(NbrSol) = GccEnt_enclosed;
289 }
290 else if (Abs(distcc2-R2-Radius(k)) < Tol) {
291 qualifier2(NbrSol) = GccEnt_outside;
292 }
293 else { qualifier2(NbrSol) = GccEnt_enclosing; }
294 if (Center.Distance(center1) <= Tolerance &&
295 Abs(Radius(k)-C1.Radius()) <= Tolerance) {
296 TheSame1(NbrSol) = 1;
297 }
298 else {
299 TheSame1(NbrSol) = 0;
300 gp_Dir2d dc1(center1.XY()-Center.XY());
301 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(k)*dc1.XY());
302 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
303 pnttg1sol(NbrSol));
304 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
305 }
306 if (Center.Distance(center2) <= Tolerance &&
307 Abs(Radius(k)-C2.Radius()) <= Tolerance) {
308 TheSame2(NbrSol) = 1;
309 }
310 else {
311 TheSame2(NbrSol) = 0;
312 gp_Dir2d dc2(center2.XY()-Center.XY());
313 pnttg2sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(k)*dc2.XY());
314 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
315 pnttg2sol(NbrSol));
316 pararg2(NbrSol)=ElCLib::Parameter(C2,pnttg2sol(NbrSol));
317 }
318 pntcen(NbrSol) = Center;
319 parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol));
320 }
321 }
322 }
323 }
324 WellDone = Standard_True;
325 }
326 }
327 }
328}
329