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 <GccAna_Pnt2dBisec.hxx>
21 #include <GccEnt_BadQualifier.hxx>
22 #include <GccEnt_QualifiedCirc.hxx>
23 #include <GccEnt_QualifiedLin.hxx>
24 #include <GccInt_Bisec.hxx>
25 #include <GccInt_IType.hxx>
26 #include <gp_Circ2d.hxx>
27 #include <gp_Dir2d.hxx>
28 #include <gp_Lin2d.hxx>
29 #include <gp_Pnt2d.hxx>
30 #include <IntAna2d_AnaIntersection.hxx>
31 #include <IntAna2d_Conic.hxx>
32 #include <IntAna2d_IntPoint.hxx>
33 #include <Precision.hxx>
34 #include <Standard_OutOfRange.hxx>
35 #include <StdFail_NotDone.hxx>
37 //=========================================================================
38 // Creation of a circle tangent to a straight line and two points. +
39 //=========================================================================
41 GccAna_Circ2d3Tan (const GccEnt_QualifiedLin& Qualified1,
42 const gp_Pnt2d& Point2 ,
43 const gp_Pnt2d& Point3 ,
44 const Standard_Real Tolerance ):
64 WellDone = Standard_False;
65 Standard_Real Tol = Abs(Tolerance);
66 gp_Dir2d dirx(1.0,0.0);
68 if (!(Qualified1.IsEnclosed() ||
69 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
70 throw GccEnt_BadQualifier();
74 //=========================================================================
76 //=========================================================================
78 gp_Lin2d L1 = Qualified1.Qualified();
79 gp_Pnt2d origin1(L1.Location());
80 gp_Dir2d dir1(L1.Direction());
81 gp_Dir2d normL1(-dir1.Y(),dir1.X());
83 if (Point2.IsEqual(Point3,Precision::Confusion())) {
84 WellDone = Standard_False;
88 GccAna_Pnt2dBisec Bis1(Point2,Point3);
89 GccAna_LinPnt2dBisec Bis2(L1,Point2);
90 if (Bis1.IsDone() && Bis2.IsDone()) {
91 const gp_Lin2d linint1(Bis1.ThisSolution());
92 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution();
93 GccInt_IType typ2 = Sol2->ArcType();
94 IntAna2d_AnaIntersection Intp;
95 if (typ2 == GccInt_Lin) {
96 gp_Lin2d linint2(Sol2->Line());
97 Intp.Perform (linint1,linint2);
99 else if (typ2 == GccInt_Par) {
100 Intp.Perform (linint1,IntAna2d_Conic(Sol2->Parabola()));
103 if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
104 (!Intp.IdenticalElements())) {
105 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
106 gp_Pnt2d Center(Intp.Point(j).Value());
107 Standard_Real dist1 = L1.Distance(Center);
108 Standard_Real dist2 = Center.Distance(Point2);
110 Standard_Real Radius=0;
111 Standard_Integer nbsol3 = 0;
112 Standard_Boolean ok = Standard_False;
113 Standard_Real difference = (((origin1.X()-Center.X())*(-dir1.Y())) + ((origin1.Y()-Center.Y())*(dir1.X())));
114 if ((Qualified1.IsEnclosed() && difference <= 0) ||
115 (Qualified1.IsOutside() && difference >= 0) ||
116 (Qualified1.IsUnqualified()))
122 if (Abs(dist2-Radius)<=Tol) {
125 else { ok = Standard_False; }
128 for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
130 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
131 // =======================================================
132 gp_Dir2d dc1(origin1.XY()-Center.XY());
133 if (!Qualified1.IsUnqualified()) {
134 qualifier1(NbrSol) = Qualified1.Qualifier();
136 else if (dc1.Dot(normL1) > 0.0) {
137 qualifier1(NbrSol) = GccEnt_outside;
139 else { qualifier1(NbrSol) = GccEnt_enclosed; }
140 qualifier2(NbrSol) = GccEnt_noqualifier;
141 qualifier3(NbrSol) = GccEnt_noqualifier;
142 TheSame1(NbrSol) = 0;
143 gp_Dir2d dc(origin1.XY()-Center.XY());
144 Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X()));
145 dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X()));
146 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
147 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
149 pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
150 TheSame2(NbrSol) = 0;
151 pnttg2sol(NbrSol) = Point2;
152 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
154 pararg2(NbrSol) = 0.;
155 TheSame3(NbrSol) = 0;
156 pnttg3sol(NbrSol) = Point3;
157 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
159 pararg3(NbrSol) = 0.;
164 WellDone = Standard_True;