1 // Created on: 1992-01-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <GccAna_Circ2d2TanOn.jxx>
25 #include <gp_Dir2d.hxx>
26 #include <gp_Ax2d.hxx>
27 #include <IntAna2d_AnaIntersection.hxx>
28 #include <IntAna2d_IntPoint.hxx>
29 #include <GccInt_IType.hxx>
30 #include <GccInt_Bisec.hxx>
31 #include <GccInt_BLine.hxx>
32 #include <GccInt_BCirc.hxx>
33 #include <IntAna2d_Conic.hxx>
34 #include <GccAna_CircPnt2dBisec.hxx>
35 #include <TColStd_Array1OfReal.hxx>
36 #include <GccEnt_BadQualifier.hxx>
38 //=========================================================================
39 // Circles tangent to circle C1, passing by point Point2 and centers +
40 // on a straight line OnLine. +
41 // We start by making difference with boundary cases that will be +
42 // processed separately. +
43 // For the general case: +
44 // ==================== +
45 // We calculate bissectrices to C1 and Point2 that give us all +
46 // possible locations of centers of all circles +
47 // tangent to C1 and passing by Point2. +
48 // We intersect these bissectrices with the straight line OnLine which +
49 // gives us the points among which we'll choose the solutions. +
50 // The choices are made using Qualifiers of C1 and C2. +
51 //=========================================================================
54 GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 ,
55 const gp_Pnt2d& Point2 ,
56 const gp_Lin2d& OnLine ,
57 const Standard_Real Tolerance ):
74 Standard_Real Tol = Abs(Tolerance);
75 WellDone = Standard_False;
77 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
78 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
79 GccEnt_BadQualifier::Raise();
82 TColStd_Array1OfReal Radius(1,2);
84 gp_Circ2d C1 = Qualified1.Qualified();
85 Standard_Real R1 = C1.Radius();
86 gp_Pnt2d center1(C1.Location());
88 //=========================================================================
89 // Processing of boundary cases. +
90 //=========================================================================
92 Standard_Real dp2l = OnLine.Distance(Point2);
93 gp_Dir2d donline(OnLine.Direction());
94 gp_Pnt2d pinterm(Point2.XY()+dp2l*gp_XY(-donline.Y(),donline.X()));
95 if (OnLine.Distance(pinterm) > Tol) {
96 pinterm = gp_Pnt2d(Point2.XY()-dp2l*gp_XY(-donline.Y(),donline.X()));
98 Standard_Real dist = pinterm.Distance(center1);
99 if (Qualified1.IsEnclosed() && Abs(R1-dist-dp2l) <= Tol) {
100 WellDone = Standard_True;
102 else if (Qualified1.IsEnclosing() && Abs(R1+dist-dp2l) <= Tol) {
103 WellDone = Standard_True;
105 else if (Qualified1.IsOutside() && Abs(dist-dp2l) <= Tol) {
106 WellDone = Standard_True;
108 else if (Qualified1.IsUnqualified() &&
109 (Abs(dist-dp2l) <= Tol || Abs(R1-dist-dp2l) <= Tol ||
110 Abs(R1+dist-dp2l) <= Tol)) {
111 WellDone = Standard_True;
115 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),dp2l);
116 // ======================================================
117 gp_Dir2d dc1(center1.XY()-pinterm.XY());
118 Standard_Real distcc1 = pinterm.Distance(center1);
119 if (!Qualified1.IsUnqualified()) {
120 qualifier1(NbrSol) = Qualified1.Qualifier();
122 else if (Abs(distcc1+dp2l-R1) < Tol) {
123 qualifier1(NbrSol) = GccEnt_enclosed;
125 else if (Abs(distcc1-R1-dp2l) < Tol) {
126 qualifier1(NbrSol) = GccEnt_outside;
128 else { qualifier1(NbrSol) = GccEnt_enclosing; }
129 qualifier2(NbrSol) = GccEnt_noqualifier;
130 pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dp2l*dc1.XY());
131 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
132 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
133 pnttg2sol(NbrSol) = Point2;
134 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
135 pntcen(NbrSol) = cirsol(NbrSol).Location();
136 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
140 //=========================================================================
142 //=========================================================================
144 GccAna_CircPnt2dBisec Bis(C1,Point2);
146 Standard_Integer nbsolution = Bis.NbSolutions();
147 for (Standard_Integer i = 1 ; i <= nbsolution; i++) {
148 Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i);
149 GccInt_IType type = Sol->ArcType();
150 IntAna2d_AnaIntersection Intp;
151 if (type == GccInt_Lin) {
152 Intp.Perform(OnLine,Sol->Line());
154 else if (type == GccInt_Cir) {
155 Intp.Perform(OnLine,Sol->Circle());
157 else if (type == GccInt_Ell) {
158 Intp.Perform(OnLine,IntAna2d_Conic(Sol->Ellipse()));
160 else if (type == GccInt_Hpr) {
161 Intp.Perform(OnLine,IntAna2d_Conic(Sol->Hyperbola()));
164 if (!Intp.IsEmpty()) {
165 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
166 gp_Pnt2d Center(Intp.Point(j).Value());
167 Standard_Real dist1 = center1.Distance(Center);
168 Standard_Integer nbsol = 1;
169 Standard_Boolean ok = Standard_False;
170 if (Qualified1.IsEnclosed()) {
171 if (dist1-C1.Radius() <= Tolerance) {
173 Radius(1) = Abs(C1.Radius()-dist1);
176 else if (Qualified1.IsOutside()) {
177 if (C1.Radius()-dist1 <= Tolerance) {
179 Radius(1) = Abs(C1.Radius()-dist1);
182 else if (Qualified1.IsEnclosing()) {
184 Radius(1) = C1.Radius()+dist1;
186 /* else if (Qualified1.IsUnqualified() && ok) {
189 Radius(1) = Abs(C1.Radius()-dist1);
190 Radius(2) = C1.Radius()+dist1;
193 else if (Qualified1.IsUnqualified() ) {
194 Standard_Real popradius = Center.Distance(Point2);
195 if (Abs(popradius-dist1)) {
197 Radius(1) = popradius;
202 for (Standard_Integer k = 1 ; k <= nbsol ; k++) {
204 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
205 // ==========================================================
206 Standard_Real distcc1 = Center.Distance(center1);
207 if (!Qualified1.IsUnqualified()) {
208 qualifier1(NbrSol) = Qualified1.Qualifier();
210 else if (Abs(distcc1+Radius(k)-R1) < Tol) {
211 qualifier1(NbrSol) = GccEnt_enclosed;
213 else if (Abs(distcc1-R1-Radius(k)) < Tol) {
214 qualifier1(NbrSol) = GccEnt_outside;
216 else { qualifier1(NbrSol) = GccEnt_enclosing; }
217 qualifier2(NbrSol) = GccEnt_noqualifier;
218 if (Center.Distance(center1) <= Tolerance &&
219 Abs(Radius(k)-C1.Radius()) <= Tolerance) {
220 TheSame1(NbrSol) = 1;
223 TheSame1(NbrSol) = 0;
224 gp_Dir2d dc1(center1.XY()-Center.XY());
225 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(k)*dc1.XY());
226 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
228 pararg1(i)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
230 TheSame2(NbrSol) = 0;
231 pnttg2sol(NbrSol) = Point2;
232 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
235 pntcen(NbrSol) = Center;
236 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
241 WellDone = Standard_True;