1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
// file GccAna_Circ2dTanOnRad.cxx, REG 08/07/91
// PRO12736 : bug quand OnLine // Ox, JCT 20/03/98
//========================================================================
// circulaire tangent a un element de type : - Cercle. +
// - Ligne. +
// - Point. +
// centre sur un deuxieme element de type : - Cercle. +
// - Ligne. +
// de rayon donne : Radius. +
//========================================================================
#include <GccAna_Circ2dTanOnRad.ixx>
#include <ElCLib.hxx>
#include <math_DirectPolynomialRoots.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <Standard_NegativeValue.hxx>
#include <gp_Dir2d.hxx>
#include <Standard_OutOfRange.hxx>
#include <StdFail_NotDone.hxx>
#include <GccEnt_BadQualifier.hxx>
typedef math_DirectPolynomialRoots Roots;
//=========================================================================
// Cercle tangent : a un cercle Qualified1 (C1). +
// centre : sur une droite OnLine. +
// de rayon : Radius. +
// +
// On initialise le tableau de solutions cirsol ainsi que tous les +
// champs. +
// On elimine en fonction du qualifieur les cas ne presentant pas de +
// solutions. +
// On resoud l equation du second degre indiquant que le point de centre +
// recherche (xc,yc) est a une distance Radius du cercle C1 et +
// sur la droite OnLine. +
// Les solutions sont representees par les cercles : +
// - de centre Pntcen(xc,yc) +
// - de rayon Radius. +
//=========================================================================
GccAna_Circ2dTanOnRad::
GccAna_Circ2dTanOnRad (const GccEnt_QualifiedCirc& Qualified1,
const gp_Lin2d& OnLine ,
const Standard_Real Radius ,
const Standard_Real Tolerance ) :
cirsol(1,4) ,
qualifier1(1,4) ,
TheSame1(1,4) ,
pnttg1sol(1,4) ,
pntcen3(1,4) ,
par1sol(1,4) ,
pararg1(1,4) ,
parcen3(1,4)
{
TheSame1.Init(0);
gp_Dir2d dirx(1.0,0.0);
Standard_Real Tol = Abs(Tolerance);
WellDone = Standard_False;
NbrSol = 0;
if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
GccEnt_BadQualifier::Raise();
return;
}
TColStd_Array1OfReal Coef(1,2);
gp_Circ2d C1 = Qualified1.Qualified();
if (Radius < 0.0) { Standard_NegativeValue::Raise(); }
else {
Standard_Integer nbsol = 0;
Standard_Integer signe = 0;
gp_Pnt2d Center;
Standard_Real xc;
Standard_Real yc;
Standard_Real R1 = C1.Radius();
Standard_Real dist = OnLine.Distance(C1.Location());
Standard_Real xdir = (OnLine.Direction()).X();
Standard_Real ydir = (OnLine.Direction()).Y();
Standard_Real lxloc = (OnLine.Location()).X();
Standard_Real lyloc = (OnLine.Location()).Y();
gp_Pnt2d center1(C1.Location());
Standard_Real x1 = center1.X();
Standard_Real y1 = center1.Y();
if (Qualified1.IsEnclosed()) {
// ============================
if (Tol < Radius-R1+dist) { WellDone = Standard_True; }
else {
if (Abs(Radius-R1+dist) < Tol) {
WellDone = Standard_True;
NbrSol = 1;
if (-ydir*(x1-lxloc)+xdir*(y1-lyloc)<0.0) {
Center = gp_Pnt2d(x1-ydir*dist,y1+xdir*dist);
}
else { Center = gp_Pnt2d(x1+ydir*dist,y1-xdir*dist); }
signe = 1;
}
else {
Coef(1) = (R1-Radius)*(R1-Radius);
nbsol = 1;
}
}
}
else if (Qualified1.IsEnclosing()) {
// ==================================
if (R1+dist-Radius > Tol) { WellDone = Standard_True; }
else {
if (R1+dist-Radius > 0.0) {
WellDone = Standard_True;
NbrSol = 1;
if (-ydir*(x1-lxloc)+xdir*(y1-lyloc)<0.0) {
Center = gp_Pnt2d(x1-ydir*dist,y1+xdir*dist);
}
else { Center = gp_Pnt2d(x1+ydir*dist,y1-xdir*dist); }
signe = -1;
}
else {
Coef(1) = (Radius-R1)*(Radius-R1);
nbsol = 1;
}
}
}
else {
// ====
if (dist-R1-Radius > Tol) { WellDone = Standard_False; }
else {
if (Abs(dist-R1-Radius) < Tol) {
WellDone = Standard_True;
NbrSol = 1;
if (-ydir*(x1-lxloc)+xdir*(y1-lyloc)<0.0) {
Center = gp_Pnt2d(x1-ydir*dist,y1+xdir*dist);
}
else { Center = gp_Pnt2d(x1+ydir*dist,y1-xdir*dist); }
signe = -1;
}
else {
if (Qualified1.IsOutside()) {
// ===========================
Coef(1) = (Radius+R1)*(Radius+R1);
nbsol = 1;
}
else {
// ====
Coef(1) = (Radius-R1)*(Radius-R1);
Coef(2) = (Radius+R1)*(Radius+R1);
nbsol = 2;
}
}
}
}
if (signe != 0) {
cirsol(1) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
// ==================================================
Standard_Real distcc1 = Center.Distance(center1);
if (!Qualified1.IsUnqualified()) {
qualifier1(1) = Qualified1.Qualifier();
}
else if (Abs(distcc1+Radius-R1) < Tol) {
qualifier1(1) = GccEnt_enclosed;
}
else if (Abs(distcc1-R1-Radius) < Tol) {
qualifier1(1) = GccEnt_outside;
}
else { qualifier1(1) = GccEnt_enclosing; }
if (Abs(Radius-R1) <= Tol) { TheSame1(1) = 1; }
else {
gp_Dir2d dir1cen(Center.X()-x1,Center.Y()-y1);
pnttg1sol(1) = gp_Pnt2d(Center.XY()+signe*Radius*dir1cen.XY());
par1sol(1)=ElCLib::Parameter(cirsol(1),pnttg1sol(1));
pararg1(1)=ElCLib::Parameter(C1,pnttg1sol(1));
}
pntcen3(1) = cirsol(NbrSol).Location();
parcen3(1)=ElCLib::Parameter(OnLine,pntcen3(1));
}
else if (nbsol > 0) {
for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
Standard_Real A,B,C;
OnLine.Coefficients(A,B,C);
Standard_Real D = A;
Standard_Real x0,y0;
if ( Abs(D) <= Tol ) {
A = B;
B = D;
x0 = y1;
y0 = x1;
}
else{
x0 = x1;
y0 = y1;
}
Roots Sol((B*B+A*A)/(A*A),
2.0*(B*C/(A*A)+(B/A)*x0-y0),
x0*x0+y0*y0+C*C/(A*A)-Coef(j)+2.0*C*x0/A);
if (Sol.IsDone()) {
for (Standard_Integer i = 1 ; i <= Sol.NbSolutions() ; i++) {
if ( Abs(D) > Tol ) {
yc = Sol.Value(i);
xc = -(B/A)*yc-C/A;
}
else {
xc = Sol.Value(i);
yc = -(B/A)*xc-C/A;
}
Center = gp_Pnt2d(xc,yc);
if (OnLine.Distance(Center)>Tol)
continue;
NbrSol++;
cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
// =======================================================
Standard_Real distcc1 = Center.Distance(center1);
if (!Qualified1.IsUnqualified()) {
qualifier1(NbrSol) = Qualified1.Qualifier();
}
else if (Abs(distcc1+Radius-R1) < Tol) {
qualifier1(NbrSol) = GccEnt_enclosed;
}
else if (Abs(distcc1-R1-Radius) < Tol) {
qualifier1(NbrSol) = GccEnt_outside;
}
else { qualifier1(NbrSol) = GccEnt_enclosing; }
gp_Dir2d dir1cen(Center.X()-x1,Center.Y()-y1);
if ((Radius > R1) || (Center.Distance(center1) > R1)) {
pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dir1cen.XY());
}
else {
pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()-Radius*dir1cen.XY());
}
pntcen3(NbrSol) = cirsol(NbrSol).Location();
par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
pnttg1sol(NbrSol));
pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen3(NbrSol));
}
WellDone = Standard_True;
}
}
}
}
}
Standard_Boolean GccAna_Circ2dTanOnRad::
IsDone () const { return WellDone; }
Standard_Integer GccAna_Circ2dTanOnRad::
NbSolutions () const { return NbrSol; }
gp_Circ2d GccAna_Circ2dTanOnRad::ThisSolution (const Standard_Integer Index) const
{
if (Index > NbrSol || Index <= 0) {
Standard_OutOfRange::Raise();
}
return cirsol(Index);
}
void GccAna_Circ2dTanOnRad::
WhichQualifier(const Standard_Integer Index ,
GccEnt_Position& Qualif1 ) const
{
if (!WellDone) { StdFail_NotDone::Raise(); }
else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
else {
Qualif1 = qualifier1(Index);
}
}
void GccAna_Circ2dTanOnRad::
Tangency1 (const Standard_Integer Index,
Standard_Real& ParSol,
Standard_Real& ParArg,
gp_Pnt2d& PntSol) const{
if (!WellDone) {
StdFail_NotDone::Raise();
}
else if (Index <= 0 ||Index > NbrSol) {
Standard_OutOfRange::Raise();
}
else {
ParSol = par1sol(Index);
ParArg = pararg1(Index);
PntSol = gp_Pnt2d(pnttg1sol(Index));
}
}
void GccAna_Circ2dTanOnRad::
CenterOn3 (const Standard_Integer Index,
Standard_Real& ParArg,
gp_Pnt2d& PntSol) const{
if (!WellDone) {
StdFail_NotDone::Raise();
}
else if (Index <= 0 ||Index > NbrSol) {
Standard_OutOfRange::Raise();
}
else {
ParArg = parcen3(Index);
PntSol = pnttg1sol(Index);
}
}
Standard_Boolean GccAna_Circ2dTanOnRad::IsTheSame1 (const Standard_Integer Index) const
{
if (!WellDone)
StdFail_NotDone::Raise();
if (Index <= 0 ||Index > NbrSol)
Standard_OutOfRange::Raise();
if (TheSame1(Index) == 0)
return Standard_False;
return Standard_True;
}
|