Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1992-01-02 |
2 | // Created by: Remi GILET | |
3 | // Copyright (c) 1992-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
7fd59977 | 17 | |
18 | #include <ElCLib.hxx> | |
42cf5bc1 | 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> | |
7fd59977 | 25 | #include <GccInt_Bisec.hxx> |
26 | #include <GccInt_BLine.hxx> | |
42cf5bc1 | 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> | |
7fd59977 | 34 | #include <IntAna2d_Conic.hxx> |
42cf5bc1 | 35 | #include <IntAna2d_IntPoint.hxx> |
36 | #include <Standard_OutOfRange.hxx> | |
37 | #include <StdFail_NotDone.hxx> | |
7fd59977 | 38 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 | 39 | |
40 | //========================================================================= | |
0d969553 Y |
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: + | |
7fd59977 | 46 | // ==================== + |
0d969553 Y |
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. + | |
7fd59977 | 53 | //========================================================================= |
7fd59977 | 54 | GccAna_Circ2d2TanOn:: |
55 | GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 , | |
56 | const gp_Pnt2d& Point2 , | |
57 | const gp_Lin2d& OnLine , | |
58 | const Standard_Real Tolerance ): | |
59 | cirsol(1,4), | |
60 | qualifier1(1,4) , | |
61 | qualifier2(1,4) , | |
62 | TheSame1(1,4) , | |
63 | TheSame2(1,4) , | |
64 | pnttg1sol(1,4) , | |
65 | pnttg2sol(1,4) , | |
66 | pntcen(1,4) , | |
67 | par1sol(1,4) , | |
68 | par2sol(1,4) , | |
69 | pararg1(1,4) , | |
70 | pararg2(1,4) , | |
71 | parcen3(1,4) | |
72 | { | |
73 | TheSame1.Init(0); | |
74 | TheSame2.Init(0); | |
75 | Standard_Real Tol = Abs(Tolerance); | |
76 | WellDone = Standard_False; | |
77 | NbrSol = 0; | |
78 | if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || | |
79 | Qualified1.IsOutside() || Qualified1.IsUnqualified())) { | |
9775fa61 | 80 | throw GccEnt_BadQualifier(); |
7fd59977 | 81 | return; |
82 | } | |
83 | TColStd_Array1OfReal Radius(1,2); | |
84 | gp_Dir2d dirx(1.,0.); | |
85 | gp_Circ2d C1 = Qualified1.Qualified(); | |
86 | Standard_Real R1 = C1.Radius(); | |
87 | gp_Pnt2d center1(C1.Location()); | |
88 | ||
89 | //========================================================================= | |
0d969553 | 90 | // Processing of boundary cases. + |
7fd59977 | 91 | //========================================================================= |
92 | ||
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())); | |
98 | } | |
99 | Standard_Real dist = pinterm.Distance(center1); | |
100 | if (Qualified1.IsEnclosed() && Abs(R1-dist-dp2l) <= Tol) { | |
101 | WellDone = Standard_True; | |
102 | } | |
103 | else if (Qualified1.IsEnclosing() && Abs(R1+dist-dp2l) <= Tol) { | |
104 | WellDone = Standard_True; | |
105 | } | |
106 | else if (Qualified1.IsOutside() && Abs(dist-dp2l) <= Tol) { | |
107 | WellDone = Standard_True; | |
108 | } | |
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; | |
113 | } | |
114 | if (WellDone) { | |
115 | NbrSol++; | |
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(); | |
122 | } | |
123 | else if (Abs(distcc1+dp2l-R1) < Tol) { | |
124 | qualifier1(NbrSol) = GccEnt_enclosed; | |
125 | } | |
126 | else if (Abs(distcc1-R1-dp2l) < Tol) { | |
127 | qualifier1(NbrSol) = GccEnt_outside; | |
128 | } | |
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)); | |
138 | return; | |
139 | } | |
140 | ||
141 | //========================================================================= | |
0d969553 | 142 | // General case. + |
7fd59977 | 143 | //========================================================================= |
144 | ||
145 | GccAna_CircPnt2dBisec Bis(C1,Point2); | |
146 | if (Bis.IsDone()) { | |
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()); | |
154 | } | |
155 | else if (type == GccInt_Cir) { | |
156 | Intp.Perform(OnLine,Sol->Circle()); | |
157 | } | |
158 | else if (type == GccInt_Ell) { | |
159 | Intp.Perform(OnLine,IntAna2d_Conic(Sol->Ellipse())); | |
160 | } | |
161 | else if (type == GccInt_Hpr) { | |
162 | Intp.Perform(OnLine,IntAna2d_Conic(Sol->Hyperbola())); | |
163 | } | |
164 | if (Intp.IsDone()) { | |
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) { | |
173 | ok = Standard_True; | |
174 | Radius(1) = Abs(C1.Radius()-dist1); | |
175 | } | |
176 | } | |
177 | else if (Qualified1.IsOutside()) { | |
178 | if (C1.Radius()-dist1 <= Tolerance) { | |
179 | ok = Standard_True; | |
180 | Radius(1) = Abs(C1.Radius()-dist1); | |
181 | } | |
182 | } | |
183 | else if (Qualified1.IsEnclosing()) { | |
184 | ok = Standard_True; | |
185 | Radius(1) = C1.Radius()+dist1; | |
186 | } | |
187 | /* else if (Qualified1.IsUnqualified() && ok) { | |
188 | ok = Standard_True; | |
189 | nbsol = 2; | |
190 | Radius(1) = Abs(C1.Radius()-dist1); | |
191 | Radius(2) = C1.Radius()+dist1; | |
192 | } | |
193 | */ | |
194 | else if (Qualified1.IsUnqualified() ) { | |
195 | Standard_Real popradius = Center.Distance(Point2); | |
196 | if (Abs(popradius-dist1)) { | |
197 | ok = Standard_True; | |
198 | Radius(1) = popradius; | |
199 | } | |
200 | } | |
201 | ||
202 | if (ok) { | |
203 | for (Standard_Integer k = 1 ; k <= nbsol ; k++) { | |
204 | NbrSol++; | |
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(); | |
210 | } | |
211 | else if (Abs(distcc1+Radius(k)-R1) < Tol) { | |
212 | qualifier1(NbrSol) = GccEnt_enclosed; | |
213 | } | |
214 | else if (Abs(distcc1-R1-Radius(k)) < Tol) { | |
215 | qualifier1(NbrSol) = GccEnt_outside; | |
216 | } | |
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; | |
222 | } | |
223 | else { | |
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), | |
228 | pnttg1sol(NbrSol)); | |
229 | pararg1(i)=ElCLib::Parameter(C1,pnttg1sol(NbrSol)); | |
230 | } | |
231 | TheSame2(NbrSol) = 0; | |
232 | pnttg2sol(NbrSol) = Point2; | |
233 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
234 | pnttg2sol(NbrSol)); | |
235 | pararg2(NbrSol)=0.; | |
236 | pntcen(NbrSol) = Center; | |
237 | parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol)); | |
238 | } | |
239 | } | |
240 | } | |
241 | } | |
242 | WellDone = Standard_True; | |
243 | } | |
244 | } | |
245 | } | |
246 | } |