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.
17 #include <GccAna_Circ2d3Tan.hxx>
18 #include <GccAna_CircPnt2dBisec.hxx>
19 #include <GccAna_Pnt2dBisec.hxx>
20 #include <GccEnt_BadQualifier.hxx>
21 #include <GccEnt_QualifiedCirc.hxx>
22 #include <GccEnt_QualifiedLin.hxx>
23 #include <GccInt_BCirc.hxx>
24 #include <GccInt_BElips.hxx>
25 #include <GccInt_BHyper.hxx>
26 #include <GccInt_BLine.hxx>
27 #include <GccInt_IType.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>
33 #include <IntAna2d_Conic.hxx>
34 #include <IntAna2d_IntPoint.hxx>
35 #include <Precision.hxx>
36 #include <Standard_OutOfRange.hxx>
37 #include <StdFail_NotDone.hxx>
38 #include <TColStd_Array1OfReal.hxx>
40 //=======================================================================
41 // Creation of a circle tangent to a circle and two points. +
42 //=======================================================================
44 GccAna_Circ2d3Tan (const GccEnt_QualifiedCirc& Qualified1 ,
45 const gp_Pnt2d& Point2 ,
46 const gp_Pnt2d& Point3 ,
47 const Standard_Real Tolerance ):
67 gp_Dir2d dirx(1.0,0.0);
68 Standard_Real Tol = Abs(Tolerance);
69 WellDone = Standard_False;
71 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
72 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
73 throw GccEnt_BadQualifier();
77 //=========================================================================
79 //=========================================================================
81 gp_Circ2d C1 = Qualified1.Qualified();
82 Standard_Real R1 = C1.Radius();
83 gp_Pnt2d center1(C1.Location());
84 TColStd_Array1OfReal Radius(1,2);
86 if (Point2.IsEqual(Point3,Precision::Confusion())) {
87 WellDone = Standard_False;
91 GccAna_Pnt2dBisec Bis1(Point2,Point3);
92 GccAna_CircPnt2dBisec Bis2(C1,Point2);
94 if (Bis1.IsDone() && Bis2.IsDone()) {
95 Standard_Integer nbsolution2 = Bis2.NbSolutions();
96 for (Standard_Integer i = 1 ; i <= nbsolution2; i++) {
97 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution(i);
98 GccInt_IType typ2 = Sol2->ArcType();
99 gp_Lin2d Sol1(Bis1.ThisSolution());
100 IntAna2d_AnaIntersection Intp;
101 if (typ2 == GccInt_Cir) {
102 Intp.Perform(Sol1,Sol2->Circle());
104 else if (typ2 == GccInt_Lin) {
105 Intp.Perform(Sol1,Sol2->Line());
107 else if (typ2 == GccInt_Hpr) {
108 Intp.Perform(Sol1,IntAna2d_Conic(Sol2->Hyperbola()));
110 else if (typ2 == GccInt_Ell) {
111 Intp.Perform(Sol1,IntAna2d_Conic(Sol2->Ellipse()));
115 if (!Intp.IsEmpty()) {
116 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
117 gp_Pnt2d Center(Intp.Point(j).Value());
118 Standard_Real dist1 = Center.Distance(center1);
119 Standard_Real dist2 = Center.Distance(Point2);
120 Standard_Real dist3 = Center.Distance(Point3);
121 Standard_Integer nbsol1 = 0;
122 // Standard_Integer nbsol2 = 0;
123 Standard_Integer nbsol3 = 0;
124 Standard_Boolean ok = Standard_False;
125 if (Qualified1.IsEnclosed()) {
126 if (dist1-R1 < Tolerance) {
127 Radius(1) = Abs(R1-dist1);
132 else if (Qualified1.IsOutside()) {
133 if (R1-dist1 < Tolerance) {
134 Radius(1) = Abs(R1-dist1);
139 else if (Qualified1.IsEnclosing()) {
142 Radius(1) = R1+dist1;
144 else if (Qualified1.IsUnqualified()) {
147 Radius(1) = Abs(R1-dist1);
148 Radius(2) = R1+dist1;
152 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
153 //pop if (Abs(dist2-Radius(ii))<=Tol && Abs(dist2-Radius(ii))<=Tol){
154 if (Abs(dist2-Radius(ii))<=Tol && Abs(dist3-Radius(ii))<=Tol){
162 // for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
163 if (NbrSol>=2) break;
165 // cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
166 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(nbsol3));
167 // ==========================================================
168 Standard_Real distcc1 = Center.Distance(center1);
169 if (!Qualified1.IsUnqualified()) {
170 qualifier1(NbrSol) = Qualified1.Qualifier();
172 else if (Abs(distcc1+Radius(nbsol3)-R1) < Tol) {
173 qualifier1(NbrSol) = GccEnt_enclosed;
175 else if (Abs(distcc1-R1-Radius(nbsol3)) < Tol) {
176 qualifier1(NbrSol) = GccEnt_outside;
178 else { qualifier1(NbrSol) = GccEnt_enclosing; }
179 qualifier2(NbrSol) = GccEnt_noqualifier;
180 qualifier3(NbrSol) = GccEnt_noqualifier;
181 if (Center.Distance(center1) <= Tolerance &&
182 Abs(Radius(nbsol3)-R1) <= Tolerance) {
183 TheSame1(NbrSol) = 1;
186 TheSame1(NbrSol) = 0;
187 gp_Dir2d dc(center1.XY()-Center.XY());
188 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(nbsol3)*dc.XY());
189 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
191 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
194 TheSame2(NbrSol) = 0;
195 pnttg2sol(NbrSol) = Point2;
196 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
199 TheSame3(NbrSol) = 0;
200 pnttg3sol(NbrSol) = Point3;
201 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
203 pararg3(NbrSol) = 0.;
208 WellDone = Standard_True;