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