Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
3 | // | |
4 | // The content of this file is subject to the Open CASCADE Technology Public | |
5 | // License Version 6.5 (the "License"). You may not use the content of this file | |
6 | // except in compliance with the License. Please obtain a copy of the License | |
7 | // at http://www.opencascade.org and read it completely before using this file. | |
8 | // | |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
11 | // | |
12 | // The Original Code and all software distributed under the License is | |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
14 | // Initial Developer hereby disclaims all such warranties, including without | |
15 | // limitation, any warranties of merchantability, fitness for a particular | |
16 | // purpose or non-infringement. Please see the License for the specific terms | |
17 | // and conditions governing the rights and limitations under the License. | |
18 | ||
7fd59977 | 19 | |
20 | //========================================================================= | |
0d969553 Y |
21 | // CREATION of a STRAIGHT LINE TANGENT to a CIRCLE or PASSING by a POINT + |
22 | // and ORTHOGONAL to a STRAIGHT LINE. + | |
7fd59977 | 23 | //========================================================================= |
24 | ||
25 | #include <GccAna_Lin2dTanPer.ixx> | |
26 | ||
27 | #include <ElCLib.hxx> | |
28 | #include <StdFail_NotDone.hxx> | |
29 | #include <gp_XY.hxx> | |
30 | #include <gp_Dir2d.hxx> | |
31 | #include <gp_Vec2d.hxx> | |
32 | #include <gp_Circ2d.hxx> | |
33 | #include <Standard_OutOfRange.hxx> | |
34 | #include <GccEnt_BadQualifier.hxx> | |
35 | #include <IntAna2d_AnaIntersection.hxx> | |
36 | #include <IntAna2d_IntPoint.hxx> | |
37 | ||
38 | //========================================================================= | |
0d969553 Y |
39 | // Straight line passing by point : ThePoint and + |
40 | // orthogonal to straight line : TheLin. + | |
41 | // Create the straight line of origin : ThePoint + | |
42 | // and direction : TheLin.Direction() turned by 90 + | |
7fd59977 | 43 | //========================================================================= |
44 | ||
45 | GccAna_Lin2dTanPer:: | |
46 | GccAna_Lin2dTanPer (const gp_Pnt2d& ThePnt , | |
47 | const gp_Lin2d& TheLin ): | |
48 | linsol(1,1), | |
49 | qualifier1(1,1) , | |
50 | pnttg1sol(1,1), | |
51 | pntint2sol(1,1), | |
52 | par1sol(1,1), | |
53 | par2sol(1,1), | |
54 | pararg1(1,1), | |
55 | pararg2(1,1) | |
56 | { | |
57 | ||
58 | linsol(1) = gp_Lin2d(ThePnt,gp_Dir2d(-(TheLin.Direction().Y()), | |
59 | // =============================================================== | |
60 | TheLin.Direction().X())); | |
61 | // ======================== | |
62 | pnttg1sol(1) = ThePnt; | |
63 | IntAna2d_AnaIntersection Intp(linsol(1),TheLin); | |
64 | if (Intp.IsDone()) { | |
65 | if (!Intp.IsEmpty()) { | |
66 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
67 | pntint2sol(1) = Intp.Point(i).Value(); | |
68 | } | |
69 | } | |
70 | } | |
71 | par1sol(1) = ElCLib::Parameter(linsol(1),pnttg1sol(1)); | |
72 | par2sol(1) = ElCLib::Parameter(linsol(1),pntint2sol(1)); | |
73 | pararg1(1) = 0.; | |
74 | pararg2(1) = ElCLib::Parameter(TheLin,pntint2sol(1)); | |
75 | NbrSol = 1; | |
76 | WellDone = Standard_True; | |
77 | } | |
78 | ||
79 | //========================================================================= | |
0d969553 Y |
80 | // Straight line passing by point : ThePnt + |
81 | // and orthogonal to circle : TheCircle. + | |
82 | // Create the straight line of origin : ThePoint + | |
83 | // and direction : (TheCircle.Location(),ThePnt). + | |
7fd59977 | 84 | //========================================================================= |
85 | ||
86 | GccAna_Lin2dTanPer:: | |
87 | GccAna_Lin2dTanPer (const gp_Pnt2d& ThePnt , | |
88 | const gp_Circ2d& TheCircle ): | |
89 | linsol(1,1), | |
90 | qualifier1(1,1) , | |
91 | pnttg1sol(1,1), | |
92 | pntint2sol(1,1), | |
93 | par1sol(1,1), | |
94 | par2sol(1,1), | |
95 | pararg1(1,1), | |
96 | pararg2(1,1) | |
97 | { | |
98 | ||
99 | linsol(1) = gp_Lin2d(ThePnt, | |
100 | // ============================ | |
101 | gp_Dir2d(TheCircle.Location().XY()-ThePnt.XY())); | |
102 | // ================================================ | |
103 | pnttg1sol(1) = ThePnt; | |
104 | IntAna2d_AnaIntersection Intp(linsol(1),TheCircle); | |
105 | if (Intp.IsDone()) { | |
106 | if (!Intp.IsEmpty()) { | |
107 | Standard_Real maxdist = RealLast(); | |
108 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
109 | if (Intp.Point(i).Value().Distance(ThePnt) < maxdist) { | |
110 | pntint2sol(1) = Intp.Point(i).Value(); | |
111 | } | |
112 | } | |
113 | } | |
114 | } | |
115 | par1sol(1) = ElCLib::Parameter(linsol(1),pnttg1sol(1)); | |
116 | par2sol(1) = ElCLib::Parameter(linsol(1),pntint2sol(1)); | |
117 | pararg1(1) = 0.; | |
118 | pararg2(1) = ElCLib::Parameter(TheCircle,pntint2sol(1)); | |
119 | NbrSol = 1; | |
120 | WellDone = Standard_True; | |
121 | } | |
122 | ||
123 | //========================================================================= | |
0d969553 Y |
124 | // Straight line tangent to circle : Qualified1 (C1) + |
125 | // and orthogonal to straight line : TheLin. + | |
126 | // Create straight line of origin : P1 (on C1) + | |
127 | // and direction : TheLin.Direction() turned by 90` + | |
7fd59977 | 128 | //========================================================================= |
129 | ||
130 | GccAna_Lin2dTanPer:: | |
131 | GccAna_Lin2dTanPer (const GccEnt_QualifiedCirc& Qualified1, | |
132 | const gp_Lin2d& TheLin ): | |
133 | linsol(1,2), | |
134 | qualifier1(1,2) , | |
135 | pnttg1sol(1,2), | |
136 | pntint2sol(1,2), | |
137 | par1sol(1,2), | |
138 | par2sol(1,2), | |
139 | pararg1(1,2), | |
140 | pararg2(1,2) | |
141 | { | |
142 | ||
143 | WellDone = Standard_False; | |
144 | Standard_Integer nbsol = 0; | |
145 | Standard_Integer signe = 0; | |
146 | NbrSol = 0; | |
147 | gp_Circ2d C1 = Qualified1.Qualified(); | |
148 | ||
149 | if (Qualified1.IsEnclosed()) { | |
150 | // ============================ | |
151 | GccEnt_BadQualifier::Raise(); | |
152 | } | |
153 | else if (Qualified1.IsEnclosing()) { | |
154 | // ================================== | |
155 | nbsol = 1; | |
156 | signe = -1; | |
157 | } | |
158 | else if (Qualified1.IsOutside()) { | |
159 | // ================================ | |
160 | nbsol = 1; | |
161 | signe = 1; | |
162 | } | |
163 | else { | |
164 | nbsol = 2; | |
165 | signe = -1; | |
166 | } | |
167 | gp_XY xy(C1.Radius()*TheLin.Direction().XY()); | |
168 | for (Standard_Integer j = 1 ; j <= nbsol ; j++) { | |
169 | signe = -signe; | |
170 | NbrSol++; | |
171 | linsol(NbrSol)=gp_Lin2d(gp_Pnt2d((C1.Location().XY()).Added(signe*xy)), | |
172 | // ======================================================================= | |
173 | gp_Dir2d(-TheLin.Direction().Y(), | |
174 | // ================================= | |
175 | TheLin.Direction().X())); | |
176 | // ======================== | |
177 | pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY()).Added(signe*xy)); | |
178 | IntAna2d_AnaIntersection Intp(linsol(NbrSol),TheLin); | |
179 | if (Intp.IsDone()) { | |
180 | if (!Intp.IsEmpty()) { | |
181 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
182 | pntint2sol(NbrSol) = Intp.Point(i).Value(); | |
183 | } | |
184 | } | |
185 | } | |
186 | par1sol(NbrSol) = ElCLib::Parameter(linsol(NbrSol),pnttg1sol(NbrSol)); | |
187 | par2sol(NbrSol) = ElCLib::Parameter(linsol(NbrSol),pntint2sol(NbrSol)); | |
188 | pararg1(NbrSol) = ElCLib::Parameter(C1,pnttg1sol(NbrSol)); | |
189 | pararg2(NbrSol) = ElCLib::Parameter(TheLin,pntint2sol(NbrSol)); | |
190 | WellDone = Standard_True; | |
191 | } | |
192 | } | |
193 | ||
194 | //========================================================================= | |
0d969553 Y |
195 | // Straight line tangent to circle : Qualified1 (C1) + |
196 | // and orthogonal to circle : TheCircle. + | |
197 | // Create straight line of origin : P1 (on C1) + | |
198 | // and direction : TheLin.Direction() turned by 90` + | |
7fd59977 | 199 | //========================================================================= |
200 | ||
201 | GccAna_Lin2dTanPer:: | |
202 | GccAna_Lin2dTanPer (const GccEnt_QualifiedCirc& Qualified1, | |
203 | const gp_Circ2d& TheCircle ): | |
204 | linsol(1,2), | |
205 | qualifier1(1,2) , | |
206 | pnttg1sol(1,2), | |
207 | pntint2sol(1,2), | |
208 | par1sol(1,2), | |
209 | par2sol(1,2), | |
210 | pararg1(1,2), | |
211 | pararg2(1,2) | |
212 | { | |
213 | ||
214 | WellDone = Standard_False; | |
215 | NbrSol = 0; | |
216 | Standard_Integer nbsol = 0; | |
217 | Standard_Integer signe = 0; | |
218 | gp_Circ2d C1 = Qualified1.Qualified(); | |
219 | ||
220 | if (Qualified1.IsEnclosed()) { | |
221 | // ============================ | |
222 | GccEnt_BadQualifier::Raise(); | |
223 | } | |
224 | else if (Qualified1.IsEnclosing()) { | |
225 | // ================================== | |
226 | nbsol = 1; | |
227 | signe = -1; | |
228 | qualifier1(1) = GccEnt_enclosing; | |
229 | } | |
230 | else if (Qualified1.IsOutside()) { | |
231 | // ================================ | |
232 | nbsol = 1; | |
233 | signe = 1; | |
234 | qualifier1(1) = GccEnt_outside; | |
235 | } | |
236 | else if (Qualified1.IsUnqualified()) { | |
237 | // ==================================== | |
238 | nbsol = 2; | |
239 | signe = -1; | |
240 | qualifier1(1) = GccEnt_enclosing; | |
241 | qualifier1(2) = GccEnt_outside; | |
242 | } | |
243 | for (Standard_Integer j = 1 ; j <= 2 ; j++) { | |
244 | NbrSol++; | |
245 | signe = -signe; | |
246 | gp_Dir2d D1(TheCircle.Location().XY()-C1.Location().XY()); | |
247 | linsol(NbrSol) = gp_Lin2d(gp_Pnt2d((C1.Location().XY())+ | |
248 | // =================================================== | |
249 | signe*(D1.XY()*C1.Radius())),gp_Dir2d(-D1.Y(),D1.X())); | |
250 | // ====================================================== | |
251 | pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY())+ | |
252 | signe*(D1.XY()*C1.Radius())); | |
253 | IntAna2d_AnaIntersection Intp(linsol(NbrSol),TheCircle); | |
254 | if (Intp.IsDone()) { | |
255 | if (!Intp.IsEmpty()) { | |
256 | Standard_Real maxdist = RealLast(); | |
257 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
258 | if (Intp.Point(i).Value().Distance(pnttg1sol(NbrSol)) < maxdist) { | |
259 | pntint2sol(NbrSol) = Intp.Point(i).Value(); | |
260 | } | |
261 | } | |
262 | } | |
263 | } | |
264 | par1sol(NbrSol) = ElCLib::Parameter(linsol(NbrSol),pnttg1sol(NbrSol)); | |
265 | par2sol(NbrSol) = ElCLib::Parameter(linsol(NbrSol),pntint2sol(NbrSol)); | |
266 | pararg1(NbrSol) = ElCLib::Parameter(C1,pnttg1sol(NbrSol)); | |
267 | pararg2(NbrSol) = ElCLib::Parameter(TheCircle,pntint2sol(NbrSol)); | |
268 | WellDone = Standard_True; | |
269 | } | |
270 | } | |
271 | ||
272 | Standard_Boolean GccAna_Lin2dTanPer:: | |
273 | IsDone () const { return WellDone; } | |
274 | ||
275 | Standard_Integer GccAna_Lin2dTanPer:: | |
276 | NbSolutions () const | |
277 | { | |
278 | if (!WellDone) { StdFail_NotDone::Raise(); } | |
279 | return NbrSol; | |
280 | } | |
281 | ||
282 | gp_Lin2d GccAna_Lin2dTanPer:: | |
283 | ThisSolution (const Standard_Integer Index) const | |
284 | { | |
285 | if (!WellDone) { StdFail_NotDone::Raise(); } | |
286 | if (Index <= 0 || Index > NbrSol) { Standard_RangeError::Raise(); } | |
287 | return linsol(Index); | |
288 | } | |
289 | ||
290 | void GccAna_Lin2dTanPer:: | |
291 | WhichQualifier(const Standard_Integer Index , | |
292 | GccEnt_Position& Qualif1 ) const | |
293 | { | |
294 | if (!WellDone) { StdFail_NotDone::Raise(); } | |
295 | if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); } | |
296 | else { | |
297 | Qualif1 = qualifier1(Index); | |
298 | } | |
299 | } | |
300 | ||
301 | void GccAna_Lin2dTanPer:: | |
302 | Tangency1 (const Standard_Integer Index, | |
303 | Standard_Real& ParSol, | |
304 | Standard_Real& ParArg, | |
305 | gp_Pnt2d& Pnt) const{ | |
306 | if (!WellDone) { StdFail_NotDone::Raise(); } | |
307 | else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); } | |
308 | else { | |
309 | ParSol = par1sol(Index); | |
310 | ParArg = pararg1(Index); | |
311 | Pnt = gp_Pnt2d(pnttg1sol(Index)); | |
312 | } | |
313 | } | |
314 | ||
315 | void GccAna_Lin2dTanPer:: | |
316 | Intersection2 (const Standard_Integer Index, | |
317 | Standard_Real& ParSol, | |
318 | Standard_Real& ParArg, | |
319 | gp_Pnt2d& PntSol) const { | |
320 | if (!WellDone) { StdFail_NotDone::Raise(); } | |
321 | else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); } | |
322 | else { | |
323 | ParSol = par2sol(Index); | |
324 | ParArg = pararg2(Index); | |
325 | PntSol = gp_Pnt2d(pntint2sol(Index)); | |
326 | } | |
327 | } | |
328 |