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
7 // under the terms of the GNU Lesser General Public 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 <GccAna_LinPnt2dBisec.hxx>
24 #include <GccAna_Lin2dBisec.hxx>
25 #include <GccInt_IType.hxx>
26 #include <GccInt_BLine.hxx>
27 #include <GccInt_BParab.hxx>
28 #include <IntAna2d_Conic.hxx>
29 #include <GccEnt_BadQualifier.hxx>
31 //=========================================================================
32 // Creation of a circle tangent to two straight lines and a point. +
33 //=========================================================================
36 GccAna_Circ2d3Tan (const GccEnt_QualifiedLin& Qualified1 ,
37 const GccEnt_QualifiedLin& Qualified2 ,
38 const gp_Pnt2d& Point3 ,
39 const Standard_Real Tolerance ):
59 gp_Dir2d dirx(1.0,0.0);
60 WellDone = Standard_False;
61 Standard_Real Tol = Abs(Tolerance);
63 if (!(Qualified1.IsEnclosed() ||
64 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
65 !(Qualified2.IsEnclosed() ||
66 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
67 GccEnt_BadQualifier::Raise();
71 pnttg3sol.Init(Point3);
73 //=========================================================================
75 //=========================================================================
77 gp_Lin2d L1 = Qualified1.Qualified();
78 gp_Lin2d L2 = Qualified2.Qualified();
79 gp_Pnt2d origin1(L1.Location());
80 gp_Dir2d dir1(L1.Direction());
81 gp_Dir2d normL1(-dir1.Y(),dir1.X());
82 gp_Pnt2d origin2(L2.Location());
83 gp_Dir2d dir2(L2.Direction());
84 gp_Dir2d normL2(-dir2.Y(),dir2.X());
86 GccAna_Lin2dBisec Bis1(L1,L2);
87 GccAna_LinPnt2dBisec Bis2(L1,Point3);
88 if (Bis1.IsDone() && Bis2.IsDone()) {
89 Standard_Integer nbsolution1 = Bis1.NbSolutions();
90 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution();
91 for (Standard_Integer i = 1 ; i <= nbsolution1; i++) {
93 gp_Lin2d Sol1(Bis1.ThisSolution(i));
95 Bis1.ThisSolution(i) ;
97 GccInt_IType typ2 = Sol2->ArcType();
98 IntAna2d_AnaIntersection Intp;
99 if (typ2 == GccInt_Lin) {
100 Intp.Perform(Bis1.ThisSolution(i),Sol2->Line());
102 else if (typ2 == GccInt_Par) {
103 Intp.Perform(Bis1.ThisSolution(i),IntAna2d_Conic(Sol2->Parabola()));
106 if (!Intp.IsEmpty()) {
107 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
108 gp_Pnt2d Center(Intp.Point(j).Value());
109 Standard_Real dist1 = L1.Distance(Center);
110 Standard_Real dist2 = L2.Distance(Center);
111 Standard_Real dist3 = Center.Distance(Point3);
112 Standard_Real Radius=0;
113 Standard_Integer nbsol1 = 0;
114 Standard_Integer nbsol2 = 0;
115 Standard_Integer nbsol3 = 0;
116 Standard_Boolean ok = Standard_False;
117 if (Qualified1.IsEnclosed()) {
118 if ((((origin1.X()-Center.X())*(-dir1.Y()))+
119 ((origin1.Y()-Center.Y())*(dir1.X())))<=0){
125 else if (Qualified1.IsOutside()) {
126 if ((((origin1.X()-Center.X())*(-dir1.Y()))+
127 ((origin1.Y()-Center.Y())*(dir1.X())))>=0){
133 else if (Qualified1.IsUnqualified()) {
138 if (Qualified2.IsEnclosed()) {
139 if ((((origin2.X()-Center.X())*(-dir2.Y()))+
140 ((origin2.Y()-Center.Y())*(dir2.X())))<=0){
141 if (Abs(dist2-Radius) < Tol) { nbsol2 = 1; }
142 else { ok = Standard_False; }
145 else if (Qualified2.IsOutside() && ok) {
146 if ((((origin2.X()-Center.X())*(-dir2.Y()))+
147 ((origin2.Y()-Center.Y())*(dir2.X())))>=0){
148 if (Abs(dist2-Radius) < Tol) { nbsol2 = 1; }
149 else { ok = Standard_False; }
152 else if (Qualified2.IsUnqualified() && ok) {
153 if (Abs(dist2-Radius) < Tol) { nbsol2 = 1; }
154 else { ok = Standard_False; }
157 if (Abs(dist3-Radius) < Tol) { nbsol3 = 1; }
158 else { ok = Standard_False; }
161 for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
163 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
164 // =======================================================
165 gp_Dir2d dc1(origin1.XY()-Center.XY());
166 if (!Qualified1.IsUnqualified()) {
167 qualifier1(NbrSol) = Qualified1.Qualifier();
169 else if (dc1.Dot(normL1) > 0.0) {
170 qualifier1(NbrSol) = GccEnt_outside;
172 else { qualifier1(NbrSol) = GccEnt_enclosed; }
173 gp_Dir2d dc2(origin2.XY()-Center.XY());
174 if (!Qualified2.IsUnqualified()) {
175 qualifier2(NbrSol) = Qualified2.Qualifier();
177 else if (dc2.Dot(normL2) > 0.0) {
178 qualifier2(NbrSol) = GccEnt_outside;
180 else { qualifier2(NbrSol) = GccEnt_enclosed; }
181 qualifier3(NbrSol) = GccEnt_noqualifier;
182 TheSame1(NbrSol) = 0;
183 gp_Dir2d dc(origin1.XY()-Center.XY());
184 Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X()));
185 dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X()));
186 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
187 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
189 pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
190 TheSame2(NbrSol) = 0;
191 dc = gp_Dir2d(origin2.XY()-Center.XY());
192 sign = dc.Dot(gp_Dir2d(-dir2.Y(),dir2.X()));
193 dc = gp_Dir2d(sign*gp_XY(-dir2.Y(),dir2.X()));
194 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
195 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
197 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
198 TheSame3(NbrSol) = 0;
199 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
201 pararg3(NbrSol) = 0.;
206 WellDone = Standard_True;