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_Lin2dBisec.hxx>
19 #include <GccAna_LinPnt2dBisec.hxx>
20 #include <GccEnt_BadQualifier.hxx>
21 #include <GccEnt_QualifiedLin.hxx>
22 #include <GccInt_BParab.hxx>
23 #include <GccInt_IType.hxx>
24 #include <gp_Circ2d.hxx>
25 #include <gp_Dir2d.hxx>
26 #include <gp_Lin2d.hxx>
27 #include <gp_Pnt2d.hxx>
28 #include <IntAna2d_AnaIntersection.hxx>
29 #include <IntAna2d_Conic.hxx>
30 #include <IntAna2d_IntPoint.hxx>
32 //=========================================================================
33 // Creation of a circle tangent to two straight lines and a point. +
34 //=========================================================================
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 throw GccEnt_BadQualifier();
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++) {
92 const gp_Lin2d Sol1(Bis1.ThisSolution(i));
93 GccInt_IType typ2 = Sol2->ArcType();
94 IntAna2d_AnaIntersection Intp;
95 if (typ2 == GccInt_Lin) {
96 Intp.Perform(Sol1,Sol2->Line());
98 else if (typ2 == GccInt_Par) {
99 Intp.Perform(Sol1,IntAna2d_Conic(Sol2->Parabola()));
102 if (!Intp.IsEmpty()) {
103 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
104 gp_Pnt2d Center(Intp.Point(j).Value());
105 Standard_Real dist1 = L1.Distance(Center);
106 Standard_Real dist2 = L2.Distance(Center);
107 Standard_Real dist3 = Center.Distance(Point3);
108 Standard_Real Radius=0;
109 Standard_Integer nbsol3 = 0;
110 Standard_Boolean ok = Standard_False;
111 if (Qualified1.IsEnclosed()) {
112 if ((((origin1.X()-Center.X())*(-dir1.Y()))+
113 ((origin1.Y()-Center.Y())*(dir1.X())))<=0){
118 else if (Qualified1.IsOutside()) {
119 if ((((origin1.X()-Center.X())*(-dir1.Y()))+
120 ((origin1.Y()-Center.Y())*(dir1.X())))>=0){
125 else if (Qualified1.IsUnqualified()) {
129 if (Qualified2.IsEnclosed()) {
130 if ((((origin2.X()-Center.X())*(-dir2.Y()))+
131 ((origin2.Y()-Center.Y())*(dir2.X())))<=0){
132 if (Abs(dist2-Radius) < Tol) { }
133 else { ok = Standard_False; }
136 else if (Qualified2.IsOutside() && ok) {
137 if ((((origin2.X()-Center.X())*(-dir2.Y()))+
138 ((origin2.Y()-Center.Y())*(dir2.X())))>=0){
139 if (Abs(dist2-Radius) < Tol) { }
140 else { ok = Standard_False; }
143 else if (Qualified2.IsUnqualified() && ok) {
144 if (Abs(dist2-Radius) < Tol) { }
145 else { ok = Standard_False; }
148 if (Abs(dist3-Radius) < Tol) { nbsol3 = 1; }
149 else { ok = Standard_False; }
152 for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
154 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
155 // =======================================================
156 gp_Dir2d dc1(origin1.XY()-Center.XY());
157 if (!Qualified1.IsUnqualified()) {
158 qualifier1(NbrSol) = Qualified1.Qualifier();
160 else if (dc1.Dot(normL1) > 0.0) {
161 qualifier1(NbrSol) = GccEnt_outside;
163 else { qualifier1(NbrSol) = GccEnt_enclosed; }
164 gp_Dir2d dc2(origin2.XY()-Center.XY());
165 if (!Qualified2.IsUnqualified()) {
166 qualifier2(NbrSol) = Qualified2.Qualifier();
168 else if (dc2.Dot(normL2) > 0.0) {
169 qualifier2(NbrSol) = GccEnt_outside;
171 else { qualifier2(NbrSol) = GccEnt_enclosed; }
172 qualifier3(NbrSol) = GccEnt_noqualifier;
173 TheSame1(NbrSol) = 0;
174 gp_Dir2d dc(origin1.XY()-Center.XY());
175 Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X()));
176 dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X()));
177 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
178 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
180 pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
181 TheSame2(NbrSol) = 0;
182 dc = gp_Dir2d(origin2.XY()-Center.XY());
183 sign = dc.Dot(gp_Dir2d(-dir2.Y(),dir2.X()));
184 dc = gp_Dir2d(sign*gp_XY(-dir2.Y(),dir2.X()));
185 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
186 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
188 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
189 TheSame3(NbrSol) = 0;
190 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
192 pararg3(NbrSol) = 0.;
197 WellDone = Standard_True;