b311480e |
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 |
5 | // |
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. |
10 | // |
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. |
13 | // |
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. |
20 | |
7fd59977 |
21 | |
22 | #include <GccAna_Circ2d2TanOn.jxx> |
23 | |
24 | #include <ElCLib.hxx> |
25 | #include <gp_Dir2d.hxx> |
26 | #include <gp_Ax2d.hxx> |
27 | #include <IntAna2d_AnaIntersection.hxx> |
28 | #include <IntAna2d_IntPoint.hxx> |
29 | #include <GccAna_Lin2dBisec.hxx> |
30 | #include <gp.hxx> |
31 | #include <GccEnt_BadQualifier.hxx> |
32 | |
33 | GccAna_Circ2d2TanOn:: |
34 | GccAna_Circ2d2TanOn (const GccEnt_QualifiedLin& Qualified1 , |
35 | const GccEnt_QualifiedLin& Qualified2 , |
36 | const gp_Circ2d& OnCirc , |
37 | const Standard_Real |
38 | #ifdef DEB |
39 | Tolerance |
40 | #endif |
41 | ): |
42 | cirsol(1,4) , |
43 | qualifier1(1,4) , |
44 | qualifier2(1,4), |
45 | TheSame1(1,4) , |
46 | TheSame2(1,4) , |
47 | pnttg1sol(1,4) , |
48 | pnttg2sol(1,4) , |
49 | pntcen(1,4) , |
50 | par1sol(1,4) , |
51 | par2sol(1,4) , |
52 | pararg1(1,4) , |
53 | pararg2(1,4) , |
54 | parcen3(1,4) |
55 | { |
56 | TheSame1.Init(0); |
57 | TheSame2.Init(0); |
58 | WellDone = Standard_False; |
59 | NbrSol = 0; |
60 | |
61 | gp_Dir2d dirx(1.,0.); |
7fd59977 |
62 | if (!(Qualified1.IsEnclosed() || |
63 | Qualified1.IsOutside() || Qualified1.IsUnqualified()) || |
64 | !(Qualified2.IsEnclosed() || |
65 | Qualified2.IsOutside() || Qualified2.IsUnqualified())) { |
66 | GccEnt_BadQualifier::Raise(); |
67 | return; |
68 | } |
69 | gp_Lin2d L1(Qualified1.Qualified()); |
70 | gp_Lin2d L2(Qualified2.Qualified()); |
71 | GccAna_Lin2dBisec Bis(L1,L2); |
72 | Standard_Integer i=0,j=0; |
73 | Standard_Integer nbsol = 0; |
74 | Standard_Real sgn = 1.; |
75 | Standard_Real s = 1.; |
76 | Standard_Boolean ok = Standard_False; |
77 | gp_Dir2d D1(L1.Direction()); |
78 | gp_Dir2d D2(L2.Direction()); |
79 | gp_Dir2d Dnor1(-D1.Y(),D1.X()); |
80 | gp_Dir2d Dnor2(-D2.Y(),D2.X()); |
81 | gp_XY XYnor1(-D1.Y(),D1.X()); |
82 | gp_XY XYnor2(-D2.Y(),D2.X()); |
83 | gp_Pnt2d originL1(L1.Location()); |
84 | gp_Pnt2d originL2(L2.Location()); |
85 | gp_XY Dloc(originL1.XY()-originL2.XY()); |
86 | if (D1.Angle(D2) <= gp::Resolution()) { |
87 | if (Qualified1.IsEnclosed()) { |
88 | if (Dloc.Dot(XYnor1) <= 0.) { ok = Standard_True; } |
89 | else { ok = Standard_False; } |
90 | } |
91 | else if (Qualified1.IsOutside()) { |
92 | if (Dloc.Dot(XYnor1) >= 0.) { ok = Standard_True; } |
93 | else { ok = Standard_False; } |
94 | } |
95 | else {ok = Standard_True; } |
96 | if (Qualified2.IsEnclosed()) { |
97 | if (Dloc.Dot(XYnor2) >= 0.) { ok = Standard_True; } |
98 | else { ok = Standard_False; } |
99 | } |
100 | else if (Qualified2.IsOutside()) { |
101 | if (Dloc.Dot(XYnor2) <= 0.) { ok = Standard_True; } |
102 | else { ok = Standard_False; } |
103 | } |
104 | else {ok = Standard_True; } |
105 | if ( ok ) { |
106 | IntAna2d_AnaIntersection Intp(Bis.ThisSolution(1),OnCirc); |
107 | if (Intp.IsDone()) { |
108 | WellDone = Standard_True; |
109 | if (!Intp.IsEmpty()) { |
110 | for (Standard_Integer l = 1 ; l <= Intp.NbPoints() ; l++) { |
111 | NbrSol++; |
112 | gp_Pnt2d pt(Intp.Point(l).Value()); |
113 | gp_Ax2d axe(pt,dirx); |
114 | cirsol(NbrSol) = gp_Circ2d(axe,L1.Distance(pt)); |
115 | // =============================================== |
116 | gp_Dir2d dc1(originL1.XY()-pt.XY()); |
117 | gp_Dir2d dc2(originL2.XY()-pt.XY()); |
118 | if (!Qualified1.IsUnqualified()) { |
119 | qualifier1(NbrSol) = Qualified1.Qualifier(); |
120 | } |
121 | else if (dc1.Dot(Dnor1) > 0.0) { |
122 | qualifier1(NbrSol) = GccEnt_outside; |
123 | } |
124 | else { qualifier1(NbrSol) = GccEnt_enclosed; } |
125 | if (!Qualified2.IsUnqualified()) { |
126 | qualifier2(NbrSol) = Qualified2.Qualifier(); |
127 | } |
128 | else if (dc2.Dot(Dnor2) > 0.0) { |
129 | qualifier2(NbrSol) = GccEnt_outside; |
130 | } |
131 | else { qualifier2(NbrSol) = GccEnt_enclosed; } |
132 | } |
133 | } |
134 | } |
135 | } |
136 | } |
137 | else if (Qualified1.IsEnclosed() && Qualified2.IsEnclosed()) { |
138 | //============================================================ |
139 | if (Bis.IsDone()) { |
140 | if (Bis.NbSolutions() == 2) { |
141 | nbsol = 1; |
142 | i = 2; |
143 | j = 1; |
144 | sgn = -1.; |
145 | } |
146 | } |
147 | } |
148 | else if (Qualified1.IsEnclosed() && Qualified2.IsOutside()) { |
149 | //=========================================================== |
150 | if (Bis.IsDone()) { |
151 | if (Bis.NbSolutions() >= 1) { |
152 | nbsol = 1; |
153 | i = 1; |
154 | j = 1; |
155 | if (D1.Angle(D2) >= 0.0) { sgn = -1.; } |
156 | } |
157 | } |
158 | } |
159 | else if (Qualified1.IsOutside() && Qualified2.IsEnclosed()) { |
160 | //=========================================================== |
161 | if (Bis.IsDone()) { |
162 | if (Bis.NbSolutions() >= 1) { |
163 | nbsol = 1; |
164 | i = 1; |
165 | j = 1; |
166 | if (D1.Angle(D2) <= 0.0) { sgn = -1.; } |
167 | } |
168 | } |
169 | } |
170 | else if (Qualified1.IsOutside() && Qualified2.IsOutside()) { |
171 | //========================================================== |
172 | if (Bis.IsDone()) { |
173 | if (Bis.NbSolutions() >= 1) { |
174 | nbsol = 1; |
175 | i = 2; |
176 | j = 1; |
177 | } |
178 | } |
179 | } |
180 | else if (Qualified1.IsUnqualified() && Qualified2.IsEnclosed()) { |
181 | //============================================================= |
182 | if (Bis.IsDone()) { |
183 | nbsol = 2; |
184 | if (Bis.NbSolutions() >= 1) { |
185 | i = 1; |
186 | j = 2; |
187 | } |
188 | if (D1.Angle(D2) >= 0.0) { s = -1.; } |
189 | else { sgn = -1.; } |
190 | } |
191 | } |
192 | else if (Qualified1.IsUnqualified() && Qualified2.IsOutside()) { |
193 | //============================================================== |
194 | if (Bis.IsDone()) { |
195 | nbsol = 2; |
196 | if (Bis.NbSolutions() >= 1) { |
197 | i = 1; |
198 | j = 2; |
199 | } |
200 | if (D1.Angle(D2) >= 0.0) { |
201 | s = -1.; |
202 | sgn = -1.; |
203 | } |
204 | } |
205 | } |
206 | else if (Qualified1.IsEnclosed() && Qualified2.IsUnqualified()) { |
207 | //=============================================================== |
208 | if (Bis.IsDone()) { |
209 | nbsol = 2; |
210 | if (Bis.NbSolutions() >= 1) { |
211 | i = 1; |
212 | j = 2; |
213 | } |
214 | if (D1.Angle(D2) >= 0.0) { sgn = -1.; } |
215 | else { s = -1.; } |
216 | } |
217 | } |
218 | else if (Qualified1.IsOutside() && Qualified2.IsUnqualified()) { |
219 | //============================================================== |
220 | if (Bis.IsDone()) { |
221 | nbsol = 2; |
222 | if (Bis.NbSolutions() >= 1) { |
223 | i = 1; |
224 | j = 2; |
225 | } |
226 | if (D1.Angle(D2) <= 0.0) { |
227 | s = -1.; |
228 | sgn = -1.; |
229 | } |
230 | } |
231 | } |
232 | else if (Qualified1.IsUnqualified() && Qualified2.IsUnqualified()) { |
233 | //================================================================== |
234 | nbsol = 4; |
235 | i = 1; |
236 | j = 2; |
237 | } |
238 | if (nbsol >= 1) { |
239 | if (Bis.IsDone()) { |
240 | Standard_Integer kk = 0; |
241 | for (Standard_Integer k = i ; k <= i+j-1 ; k++) { |
242 | kk++; |
243 | IntAna2d_AnaIntersection Intp(Bis.ThisSolution(k),OnCirc); |
244 | if (Intp.IsDone()) { |
245 | if (!Intp.IsEmpty()) { |
246 | for (Standard_Integer l = 1 ; l <= Intp.NbPoints() ; l++) { |
247 | gp_Vec2d V(Intp.Point(l).Value(), |
248 | Bis.ThisSolution(k).Location()); |
249 | if ((kk==1 && sgn*V.Dot(Bis.ThisSolution(k).Direction())>=0.0)|| |
250 | (kk==2 && sgn*s*V.Dot(Bis.ThisSolution(k).Direction())>=0.0) |
251 | || nbsol == 4) { |
252 | NbrSol++; |
253 | gp_Pnt2d pt(Intp.Point(i).Value()); |
254 | gp_Ax2d axe(pt,dirx); |
255 | cirsol(NbrSol) = gp_Circ2d(axe, |
256 | // =============================== |
257 | L1.Distance(Intp.Point(l).Value())); |
258 | // =================================== |
259 | gp_Dir2d dc1(originL1.XY()-pt.XY()); |
260 | gp_Dir2d dc2(originL2.XY()-pt.XY()); |
261 | if (!Qualified1.IsUnqualified()) { |
262 | qualifier1(NbrSol) = Qualified1.Qualifier(); |
263 | } |
264 | else if (dc1.Dot(Dnor1) > 0.0) { |
265 | qualifier1(NbrSol) = GccEnt_outside; |
266 | } |
267 | else { qualifier1(NbrSol) = GccEnt_enclosed; } |
268 | if (!Qualified2.IsUnqualified()) { |
269 | qualifier2(NbrSol) = Qualified2.Qualifier(); |
270 | } |
271 | else if (dc2.Dot(Dnor2) > 0.0) { |
272 | qualifier2(NbrSol) = GccEnt_outside; |
273 | } |
274 | else { qualifier2(NbrSol) = GccEnt_enclosed; } |
275 | } |
276 | } |
277 | } |
278 | WellDone = Standard_True; |
279 | } |
280 | } |
281 | } |
282 | } |
283 | if (NbrSol > 0) { |
284 | for (i =1 ; i <= NbrSol ; i++) { |
285 | gp_Pnt2d pbid(cirsol(i).Location()); |
286 | Standard_Real Radius = cirsol(i).Radius(); |
287 | gp_Dir2d dc2(originL1.XY()-pbid.XY()); |
288 | Standard_Real sign = dc2.Dot(gp_Dir2d(-L1.Direction().Y(), |
289 | L1.Direction().X())); |
290 | dc2 = gp_Dir2d(sign*gp_XY(-L1.Direction().Y(),L1.Direction().X())); |
291 | pnttg1sol(i) = gp_Pnt2d(pbid.XY()+Radius*dc2.XY()); |
292 | dc2 = gp_Dir2d(originL2.XY()-pbid.XY()); |
293 | sign = dc2.Dot(gp_Dir2d(-L2.Direction().Y(),L2.Direction().X())); |
294 | dc2 = gp_Dir2d(sign*gp_XY(-L2.Direction().Y(),L2.Direction().X())); |
295 | pnttg2sol(i) = gp_Pnt2d(pbid.XY()+Radius*dc2.XY()); |
296 | pntcen(i) = pbid; |
297 | par1sol(i)=ElCLib::Parameter(cirsol(i),pnttg1sol(i)); |
298 | pararg1(i)=ElCLib::Parameter(L1,pnttg1sol(i)); |
299 | par2sol(i)=ElCLib::Parameter(cirsol(i),pnttg2sol(i)); |
300 | pararg2(i)=ElCLib::Parameter(L2,pnttg2sol(i)); |
301 | parcen3(i)=ElCLib::Parameter(OnCirc,pntcen(i)); |
302 | } |
303 | } |
304 | } |
305 | |