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 GccEnt_BadQualifier::Raise();
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 gp_Lin2d linint1(Bis1.ThisSolution());
92 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution();
93 GccInt_IType typ2 = Sol2->ArcType();
95 gp_Lin2d linintb(Bis1.ThisSolution());
99 IntAna2d_AnaIntersection Intp;
100 if (typ2 == GccInt_Lin) {
101 gp_Lin2d linint2(Sol2->Line());
102 Intp.Perform (linint1,linint2);
104 else if (typ2 == GccInt_Par) {
105 Intp.Perform (linint1,IntAna2d_Conic(Sol2->Parabola()));
108 if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
109 (!Intp.IdenticalElements())) {
110 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
111 gp_Pnt2d Center(Intp.Point(j).Value());
112 Standard_Real dist1 = L1.Distance(Center);
113 Standard_Real dist2 = Center.Distance(Point2);
115 Standard_Real Radius=0;
116 Standard_Integer nbsol3 = 0;
117 Standard_Boolean ok = Standard_False;
118 Standard_Real difference = (((origin1.X()-Center.X())*(-dir1.Y())) + ((origin1.Y()-Center.Y())*(dir1.X())));
119 if ((Qualified1.IsEnclosed() && difference <= 0) ||
120 (Qualified1.IsOutside() && difference >= 0) ||
121 (Qualified1.IsUnqualified()))
127 if (Abs(dist2-Radius)<=Tol) {
130 else { ok = Standard_False; }
133 for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
135 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
136 // =======================================================
137 gp_Dir2d dc1(origin1.XY()-Center.XY());
138 if (!Qualified1.IsUnqualified()) {
139 qualifier1(NbrSol) = Qualified1.Qualifier();
141 else if (dc1.Dot(normL1) > 0.0) {
142 qualifier1(NbrSol) = GccEnt_outside;
144 else { qualifier1(NbrSol) = GccEnt_enclosed; }
145 qualifier2(NbrSol) = GccEnt_noqualifier;
146 qualifier3(NbrSol) = GccEnt_noqualifier;
147 TheSame1(NbrSol) = 0;
148 gp_Dir2d dc(origin1.XY()-Center.XY());
149 Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X()));
150 dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X()));
151 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
152 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
154 pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
155 TheSame2(NbrSol) = 0;
156 pnttg2sol(NbrSol) = Point2;
157 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
159 pararg2(NbrSol) = 0.;
160 TheSame3(NbrSol) = 0;
161 pnttg3sol(NbrSol) = Point3;
162 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
164 pararg3(NbrSol) = 0.;
169 WellDone = Standard_True;