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