1 // Created on: 1992-01-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <GccAna_Circ2d2TanOn.hxx>
20 #include <GccAna_CircPnt2dBisec.hxx>
21 #include <GccEnt_BadQualifier.hxx>
22 #include <GccEnt_QualifiedCirc.hxx>
23 #include <GccEnt_QualifiedLin.hxx>
24 #include <GccInt_BCirc.hxx>
25 #include <GccInt_Bisec.hxx>
26 #include <GccInt_BLine.hxx>
27 #include <GccInt_IType.hxx>
28 #include <gp_Ax2d.hxx>
29 #include <gp_Circ2d.hxx>
30 #include <gp_Dir2d.hxx>
31 #include <gp_Lin2d.hxx>
32 #include <gp_Pnt2d.hxx>
33 #include <IntAna2d_AnaIntersection.hxx>
34 #include <IntAna2d_Conic.hxx>
35 #include <IntAna2d_IntPoint.hxx>
36 #include <Standard_OutOfRange.hxx>
37 #include <StdFail_NotDone.hxx>
38 #include <TColStd_Array1OfReal.hxx>
40 //=========================================================================
41 // Circles tangent to circle C1, passing by point Point2 and centers +
42 // on a straight line OnLine. +
43 // We start by making difference with boundary cases that will be +
44 // processed separately. +
45 // For the general case: +
46 // ==================== +
47 // We calculate bissectrices to C1 and Point2 that give us all +
48 // possible locations of centers of all circles +
49 // tangent to C1 and passing by Point2. +
50 // We intersect these bissectrices with the straight line OnLine which +
51 // gives us the points among which we'll choose the solutions. +
52 // The choices are made using Qualifiers of C1 and C2. +
53 //=========================================================================
55 GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 ,
56 const gp_Pnt2d& Point2 ,
57 const gp_Lin2d& OnLine ,
58 const Standard_Real Tolerance ):
75 Standard_Real Tol = Abs(Tolerance);
76 WellDone = Standard_False;
78 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
79 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
80 GccEnt_BadQualifier::Raise();
83 TColStd_Array1OfReal Radius(1,2);
85 gp_Circ2d C1 = Qualified1.Qualified();
86 Standard_Real R1 = C1.Radius();
87 gp_Pnt2d center1(C1.Location());
89 //=========================================================================
90 // Processing of boundary cases. +
91 //=========================================================================
93 Standard_Real dp2l = OnLine.Distance(Point2);
94 gp_Dir2d donline(OnLine.Direction());
95 gp_Pnt2d pinterm(Point2.XY()+dp2l*gp_XY(-donline.Y(),donline.X()));
96 if (OnLine.Distance(pinterm) > Tol) {
97 pinterm = gp_Pnt2d(Point2.XY()-dp2l*gp_XY(-donline.Y(),donline.X()));
99 Standard_Real dist = pinterm.Distance(center1);
100 if (Qualified1.IsEnclosed() && Abs(R1-dist-dp2l) <= Tol) {
101 WellDone = Standard_True;
103 else if (Qualified1.IsEnclosing() && Abs(R1+dist-dp2l) <= Tol) {
104 WellDone = Standard_True;
106 else if (Qualified1.IsOutside() && Abs(dist-dp2l) <= Tol) {
107 WellDone = Standard_True;
109 else if (Qualified1.IsUnqualified() &&
110 (Abs(dist-dp2l) <= Tol || Abs(R1-dist-dp2l) <= Tol ||
111 Abs(R1+dist-dp2l) <= Tol)) {
112 WellDone = Standard_True;
116 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),dp2l);
117 // ======================================================
118 gp_Dir2d dc1(center1.XY()-pinterm.XY());
119 Standard_Real distcc1 = pinterm.Distance(center1);
120 if (!Qualified1.IsUnqualified()) {
121 qualifier1(NbrSol) = Qualified1.Qualifier();
123 else if (Abs(distcc1+dp2l-R1) < Tol) {
124 qualifier1(NbrSol) = GccEnt_enclosed;
126 else if (Abs(distcc1-R1-dp2l) < Tol) {
127 qualifier1(NbrSol) = GccEnt_outside;
129 else { qualifier1(NbrSol) = GccEnt_enclosing; }
130 qualifier2(NbrSol) = GccEnt_noqualifier;
131 pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dp2l*dc1.XY());
132 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
133 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
134 pnttg2sol(NbrSol) = Point2;
135 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
136 pntcen(NbrSol) = cirsol(NbrSol).Location();
137 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
141 //=========================================================================
143 //=========================================================================
145 GccAna_CircPnt2dBisec Bis(C1,Point2);
147 Standard_Integer nbsolution = Bis.NbSolutions();
148 for (Standard_Integer i = 1 ; i <= nbsolution; i++) {
149 Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i);
150 GccInt_IType type = Sol->ArcType();
151 IntAna2d_AnaIntersection Intp;
152 if (type == GccInt_Lin) {
153 Intp.Perform(OnLine,Sol->Line());
155 else if (type == GccInt_Cir) {
156 Intp.Perform(OnLine,Sol->Circle());
158 else if (type == GccInt_Ell) {
159 Intp.Perform(OnLine,IntAna2d_Conic(Sol->Ellipse()));
161 else if (type == GccInt_Hpr) {
162 Intp.Perform(OnLine,IntAna2d_Conic(Sol->Hyperbola()));
165 if (!Intp.IsEmpty()) {
166 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
167 gp_Pnt2d Center(Intp.Point(j).Value());
168 Standard_Real dist1 = center1.Distance(Center);
169 Standard_Integer nbsol = 1;
170 Standard_Boolean ok = Standard_False;
171 if (Qualified1.IsEnclosed()) {
172 if (dist1-C1.Radius() <= Tolerance) {
174 Radius(1) = Abs(C1.Radius()-dist1);
177 else if (Qualified1.IsOutside()) {
178 if (C1.Radius()-dist1 <= Tolerance) {
180 Radius(1) = Abs(C1.Radius()-dist1);
183 else if (Qualified1.IsEnclosing()) {
185 Radius(1) = C1.Radius()+dist1;
187 /* else if (Qualified1.IsUnqualified() && ok) {
190 Radius(1) = Abs(C1.Radius()-dist1);
191 Radius(2) = C1.Radius()+dist1;
194 else if (Qualified1.IsUnqualified() ) {
195 Standard_Real popradius = Center.Distance(Point2);
196 if (Abs(popradius-dist1)) {
198 Radius(1) = popradius;
203 for (Standard_Integer k = 1 ; k <= nbsol ; k++) {
205 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
206 // ==========================================================
207 Standard_Real distcc1 = Center.Distance(center1);
208 if (!Qualified1.IsUnqualified()) {
209 qualifier1(NbrSol) = Qualified1.Qualifier();
211 else if (Abs(distcc1+Radius(k)-R1) < Tol) {
212 qualifier1(NbrSol) = GccEnt_enclosed;
214 else if (Abs(distcc1-R1-Radius(k)) < Tol) {
215 qualifier1(NbrSol) = GccEnt_outside;
217 else { qualifier1(NbrSol) = GccEnt_enclosing; }
218 qualifier2(NbrSol) = GccEnt_noqualifier;
219 if (Center.Distance(center1) <= Tolerance &&
220 Abs(Radius(k)-C1.Radius()) <= Tolerance) {
221 TheSame1(NbrSol) = 1;
224 TheSame1(NbrSol) = 0;
225 gp_Dir2d dc1(center1.XY()-Center.XY());
226 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(k)*dc1.XY());
227 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
229 pararg1(i)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
231 TheSame2(NbrSol) = 0;
232 pnttg2sol(NbrSol) = Point2;
233 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
236 pntcen(NbrSol) = Center;
237 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
242 WellDone = Standard_True;