1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <GccAna_Circ2d3Tan.jxx>
18 #include <IntAna2d_AnaIntersection.hxx>
19 #include <IntAna2d_IntPoint.hxx>
20 #include <gp_Lin2d.hxx>
21 #include <gp_Circ2d.hxx>
22 #include <gp_Dir2d.hxx>
23 #include <TColStd_Array1OfReal.hxx>
24 #include <GccAna_CircPnt2dBisec.hxx>
25 #include <GccAna_Pnt2dBisec.hxx>
26 #include <GccInt_IType.hxx>
27 #include <GccInt_BCirc.hxx>
28 #include <GccInt_BLine.hxx>
29 #include <GccInt_BElips.hxx>
30 #include <GccInt_BHyper.hxx>
31 #include <IntAna2d_Conic.hxx>
32 #include <GccEnt_BadQualifier.hxx>
33 #include <Precision.hxx>
35 //=======================================================================
36 // Creation of a circle tangent to a circle and two points. +
37 //=======================================================================
40 GccAna_Circ2d3Tan (const GccEnt_QualifiedCirc& Qualified1 ,
41 const gp_Pnt2d& Point2 ,
42 const gp_Pnt2d& Point3 ,
43 const Standard_Real Tolerance ):
63 gp_Dir2d dirx(1.0,0.0);
64 Standard_Real Tol = Abs(Tolerance);
65 WellDone = Standard_False;
67 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
68 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
69 GccEnt_BadQualifier::Raise();
73 //=========================================================================
75 //=========================================================================
77 gp_Circ2d C1 = Qualified1.Qualified();
78 Standard_Real R1 = C1.Radius();
79 gp_Pnt2d center1(C1.Location());
80 TColStd_Array1OfReal Radius(1,2);
82 if (Point2.IsEqual(Point3,Precision::Confusion())) {
83 WellDone = Standard_False;
87 GccAna_Pnt2dBisec Bis1(Point2,Point3);
88 GccAna_CircPnt2dBisec Bis2(C1,Point2);
90 if (Bis1.IsDone() && Bis2.IsDone()) {
91 Standard_Integer nbsolution2 = Bis2.NbSolutions();
92 for (Standard_Integer i = 1 ; i <= nbsolution2; i++) {
93 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution(i);
94 GccInt_IType typ2 = Sol2->ArcType();
95 gp_Lin2d Sol1(Bis1.ThisSolution());
96 IntAna2d_AnaIntersection Intp;
97 if (typ2 == GccInt_Cir) {
98 Intp.Perform(Sol1,Sol2->Circle());
100 else if (typ2 == GccInt_Lin) {
101 Intp.Perform(Sol1,Sol2->Line());
103 else if (typ2 == GccInt_Hpr) {
104 Intp.Perform(Sol1,IntAna2d_Conic(Sol2->Hyperbola()));
106 else if (typ2 == GccInt_Ell) {
107 Intp.Perform(Sol1,IntAna2d_Conic(Sol2->Ellipse()));
111 if (!Intp.IsEmpty()) {
112 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
113 gp_Pnt2d Center(Intp.Point(j).Value());
114 Standard_Real dist1 = Center.Distance(center1);
115 Standard_Real dist2 = Center.Distance(Point2);
116 Standard_Real dist3 = Center.Distance(Point3);
117 Standard_Integer nbsol1 = 0;
118 // Standard_Integer nbsol2 = 0;
119 Standard_Integer nbsol3 = 0;
120 Standard_Boolean ok = Standard_False;
121 if (Qualified1.IsEnclosed()) {
122 if (dist1-R1 < Tolerance) {
123 Radius(1) = Abs(R1-dist1);
128 else if (Qualified1.IsOutside()) {
129 if (R1-dist1 < Tolerance) {
130 Radius(1) = Abs(R1-dist1);
135 else if (Qualified1.IsEnclosing()) {
138 Radius(1) = R1+dist1;
140 else if (Qualified1.IsUnqualified()) {
143 Radius(1) = Abs(R1-dist1);
144 Radius(2) = R1+dist1;
148 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
149 //pop if (Abs(dist2-Radius(ii))<=Tol && Abs(dist2-Radius(ii))<=Tol){
150 if (Abs(dist2-Radius(ii))<=Tol && Abs(dist3-Radius(ii))<=Tol){
158 // for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
159 if (NbrSol>=2) break;
161 // cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
162 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(nbsol3));
163 // ==========================================================
164 Standard_Real distcc1 = Center.Distance(center1);
165 if (!Qualified1.IsUnqualified()) {
166 qualifier1(NbrSol) = Qualified1.Qualifier();
168 else if (Abs(distcc1+Radius(nbsol3)-R1) < Tol) {
169 qualifier1(NbrSol) = GccEnt_enclosed;
171 else if (Abs(distcc1-R1-Radius(nbsol3)) < Tol) {
172 qualifier1(NbrSol) = GccEnt_outside;
174 else { qualifier1(NbrSol) = GccEnt_enclosing; }
175 qualifier2(NbrSol) = GccEnt_noqualifier;
176 qualifier3(NbrSol) = GccEnt_noqualifier;
177 if (Center.Distance(center1) <= Tolerance &&
178 Abs(Radius(nbsol3)-R1) <= Tolerance) {
179 TheSame1(NbrSol) = 1;
182 TheSame1(NbrSol) = 0;
183 gp_Dir2d dc(center1.XY()-Center.XY());
184 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(nbsol3)*dc.XY());
185 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
187 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
190 TheSame2(NbrSol) = 0;
191 pnttg2sol(NbrSol) = Point2;
192 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
195 TheSame3(NbrSol) = 0;
196 pnttg3sol(NbrSol) = Point3;
197 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
199 pararg3(NbrSol) = 0.;
204 WellDone = Standard_True;