0022312: Translation of french commentaries in OCCT files
[occt.git] / src / GccAna / GccAna_Circ2d2TanOn_1.cxx
CommitLineData
7fd59977 1// File: GccAna_Circ2d2TanOn_1.cxx
2// Created: Thu Jan 2 15:50:43 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_CircLin2dBisec.hxx>
14#include <GccInt_IType.hxx>
15#include <GccInt_BCirc.hxx>
16#include <IntAna2d_Conic.hxx>
17#include <GccEnt_BadQualifier.hxx>
18
19//=========================================================================
20// Creation d un cercle tangent a un Cercle C1 et a une Droite L2. +
21// centre sur une Droite. +
22// Nous commencons par distinguer les differents cas limites que nous +
23// allons traiter separement. +
24// Pour le cas general: +
25// ==================== +
26// Nous calculons les bissectrices a C1 et L2 qui nous donnent +
27// l ensemble des lieux possibles des centres de tous les cercles +
28// tangents a C1 et L2. +
29// Nous intersectons ces bissectrices avec la droite OnLine ce qui nous +
30// donne les points parmis lesquels nous allons choisir les solutions. +
31// Les choix s effectuent a partir des Qualifieurs qualifiant C1 et L2. +
32//=========================================================================
33
34GccAna_Circ2d2TanOn::
35 GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 ,
36 const GccEnt_QualifiedLin& Qualified2 ,
37 const gp_Lin2d& OnLine ,
38 const Standard_Real Tolerance ):
39 cirsol(1,4) ,
40 qualifier1(1,4) ,
41 qualifier2(1,4),
42 TheSame1(1,4) ,
43 TheSame2(1,4) ,
44 pnttg1sol(1,4) ,
45 pnttg2sol(1,4) ,
46 pntcen(1,4) ,
47 par1sol(1,4) ,
48 par2sol(1,4) ,
49 pararg1(1,4) ,
50 pararg2(1,4) ,
51 parcen3(1,4)
52{
53
54 TheSame1.Init(0);
55 TheSame2.Init(0);
56 WellDone = Standard_False;
57 NbrSol = 0;
58 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
59 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
60 !(Qualified2.IsEnclosed() ||
61 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
62 GccEnt_BadQualifier::Raise();
63 return;
64 }
65 Standard_Real Tol = Abs(Tolerance);
66 Standard_Real Radius=0;
67 Standard_Boolean ok = Standard_False;
68 gp_Dir2d dirx(1.,0.);
69 gp_Circ2d C1 = Qualified1.Qualified();
70 gp_Lin2d L2 = Qualified2.Qualified();
71 Standard_Real R1 = C1.Radius();
72 gp_Pnt2d center1(C1.Location());
73 gp_Pnt2d origin2(L2.Location());
74 gp_Dir2d dirL2(L2.Direction());
75 gp_Dir2d normL2(-dirL2.Y(),dirL2.X());
76
77//=========================================================================
78// Traitement des cas limites. +
79//=========================================================================
80
81 Standard_Real distcl = OnLine.Distance(center1);
82 gp_Pnt2d pinterm(center1.XY()+distcl*
83 gp_XY(-OnLine.Direction().Y(),OnLine.Direction().X()));
84 if (OnLine.Distance(pinterm) > Tolerance) {
85 pinterm = gp_Pnt2d(center1.XY()+distcl*
86 gp_XY(-OnLine.Direction().Y(),OnLine.Direction().X()));
87 }
88 Standard_Real dist2 = L2.Distance(pinterm);
89 if (Qualified1.IsEnclosed() || Qualified1.IsOutside()) {
90 if (Abs(distcl-R1-dist2) <= Tol) { ok = Standard_True; }
91 }
92 else if (Qualified1.IsEnclosing()) {
93 if (Abs(dist2-distcl-R1) <= Tol) { ok = Standard_True; }
94 }
95 else if (Qualified1.IsUnqualified()) { ok = Standard_True; }
96 else {
97 GccEnt_BadQualifier::Raise();
98 return;
99 }
100 if (ok) {
101 if (Qualified2.IsOutside()) {
102 gp_Pnt2d pbid(pinterm.XY()+dist2*gp_XY(-dirL2.Y(),dirL2.X()));
103 if (L2.Distance(pbid) <= Tol) { WellDone = Standard_True; }
104 }
105 else if (Qualified2.IsEnclosed()) {
106 gp_Pnt2d pbid(pinterm.XY()-dist2*gp_XY(-dirL2.Y(),dirL2.X()));
107 if (L2.Distance(pbid) <= Tol) { WellDone = Standard_True; }
108 }
109 else if (Qualified2.IsUnqualified()) { WellDone = Standard_False; }
110 else {
111 GccEnt_BadQualifier::Raise();
112 return;
113 }
114 }
115 if (WellDone) {
116 NbrSol++;
117 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),dist2);
118// =======================================================
119 gp_Dir2d dc1(center1.XY()-pinterm.XY());
120 gp_Dir2d dc2(origin2.XY()-pinterm.XY());
121 Standard_Real distcc1 = pinterm.Distance(center1);
122 if (!Qualified1.IsUnqualified()) {
123 qualifier1(NbrSol) = Qualified1.Qualifier();
124 }
125 else if (Abs(distcc1+dist2-R1) < Tol) {
126 qualifier1(NbrSol) = GccEnt_enclosed;
127 }
128 else if (Abs(distcc1-R1-dist2) < Tol) {
129 qualifier1(NbrSol) = GccEnt_outside;
130 }
131 else { qualifier1(NbrSol) = GccEnt_enclosing; }
132 if (!Qualified2.IsUnqualified()) {
133 qualifier2(NbrSol) = Qualified2.Qualifier();
134 }
135 else if (dc2.Dot(normL2) > 0.0) {
136 qualifier2(NbrSol) = GccEnt_outside;
137 }
138 else { qualifier2(NbrSol) = GccEnt_enclosed; }
139
140 Standard_Real sign = dc2.Dot(gp_Dir2d(-dirL2.Y(),dirL2.X()));
141 dc2 = gp_Dir2d(sign*gp_XY(-dirL2.Y(),dirL2.X()));
142 pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dist2*dc1.XY());
143 pnttg2sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dist2*dc2.XY());
144 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
145 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
146 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
147 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
148 pntcen(NbrSol) = cirsol(NbrSol).Location();
149 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
150 return;
151 }
152
153//=========================================================================
154// Cas general. +
155//=========================================================================
156
157 GccAna_CircLin2dBisec Bis(C1,L2);
158 if (Bis.IsDone()) {
159 Standard_Integer nbsolution = Bis.NbSolutions();
160 for (Standard_Integer i = 1 ; i <= nbsolution; i++) {
161 Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i);
162 GccInt_IType type = Sol->ArcType();
163 IntAna2d_AnaIntersection Intp;
164 if (type == GccInt_Lin) {
165 Intp.Perform(OnLine,Sol->Line());
166 }
167 else if (type == GccInt_Par) {
168 Intp.Perform(OnLine,IntAna2d_Conic(Sol->Parabola()));
169 }
170 if (Intp.IsDone()) {
171 if (!Intp.IsEmpty()) {
172 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
173 gp_Pnt2d Center(Intp.Point(j).Value());
174 Standard_Real dist1 = Center.Distance(center1);
175 dist2 = L2.Distance(Center);
176// Standard_Integer nbsol = 1;
177 ok = Standard_False;
178 if (Qualified1.IsEnclosed()) {
179 if (dist1-R1 < Tolerance) {
180 if (Abs(Abs(R1-dist1)-dist2)<Tolerance) { ok=Standard_True; }
181 }
182 }
183 else if (Qualified1.IsOutside()) {
184 if (R1-dist1 < Tolerance) {
185 if (Abs(Abs(R1-dist1)-dist2)<Tolerance) { ok=Standard_True; }
186 }
187 }
188 else if (Qualified1.IsEnclosing() || Qualified1.IsUnqualified()) {
189 ok = Standard_True;
190 }
191 if (Qualified2.IsEnclosed() && ok) {
192 if ((((origin2.X()-Center.X())*(-dirL2.Y()))+
193 ((origin2.Y()-Center.Y())*(dirL2.X())))<=0){
194 ok = Standard_True;
195 Radius = dist2;
196 }
197 }
198 else if (Qualified2.IsOutside() && ok) {
199 if ((((origin2.X()-Center.X())*(-dirL2.Y()))+
200 ((origin2.Y()-Center.Y())*(dirL2.X())))>=0){
201 ok = Standard_True;
202 Radius = dist2;
203 }
204 }
205 else if (Qualified2.IsUnqualified() && ok) {
206 ok = Standard_True;
207 Radius = dist2;
208 }
209 if (ok) {
210 NbrSol++;
211 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
212// =======================================================
213 gp_Dir2d dc1(center1.XY()-Center.XY());
214 gp_Dir2d dc2(origin2.XY()-Center.XY());
215 Standard_Real distcc1 = Center.Distance(center1);
216 if (!Qualified1.IsUnqualified()) {
217 qualifier1(NbrSol) = Qualified1.Qualifier();
218 }
219 else if (Abs(distcc1+Radius-R1) < Tol) {
220 qualifier1(NbrSol) = GccEnt_enclosed;
221 }
222 else if (Abs(distcc1-R1-Radius) < Tol) {
223 qualifier1(NbrSol) = GccEnt_outside;
224 }
225 else { qualifier1(NbrSol) = GccEnt_enclosing; }
226 if (!Qualified2.IsUnqualified()) {
227 qualifier2(NbrSol) = Qualified2.Qualifier();
228 }
229 else if (dc2.Dot(normL2) > 0.0) {
230 qualifier2(NbrSol) = GccEnt_outside;
231 }
232 else { qualifier2(NbrSol) = GccEnt_enclosed; }
233 if (Center.Distance(center1) <= Tolerance &&
234 Abs(Radius-C1.Radius()) <= Tolerance) {
235 TheSame1(NbrSol) = 1;
236 }
237 else {
238 TheSame1(NbrSol) = 0;
239 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc1.XY());
240 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
241 pnttg1sol(NbrSol));
242 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
243 }
244 TheSame2(NbrSol) = 0;
245 Standard_Real sign = dc2.Dot(gp_Dir2d(-dirL2.Y(),dirL2.X()));
246 dc2 = gp_Dir2d(sign*gp_XY(-dirL2.Y(),dirL2.X()));
247 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc2.XY());
248 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
249 pnttg2sol(NbrSol));
250 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
251 pntcen(NbrSol) = Center;
252 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
253 }
254 }
255 }
256 WellDone = Standard_True;
257 }
258 }
259 }
260 }
261
262
263
264
265
266