summaryrefslogtreecommitdiff
path: root/src/GccAna/GccAna_Circ2d2TanRad_4.cxx
blob: c232533991791318f843e23a8e469d87f5e1bc7a (plain)
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
// File:	GccAna_Circ2d2TanRad_4.cxx
// Created:	Tue Sep 24 09:15:20 1991
// Author:	Remi GILET
//		<reg@topsn2>

#include <GccAna_Circ2d2TanRad.jxx>

#include <ElCLib.hxx>
#include <gp_Circ2d.hxx>
#include <gp_Lin2d.hxx>
#include <gp_Ax2d.hxx>
#include <IntAna2d_AnaIntersection.hxx>
#include <IntAna2d_IntPoint.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <Standard_NegativeValue.hxx>
#include <gp.hxx>
#include <GccEnt_BadQualifier.hxx>

#include <Precision.hxx>

// circulaire tangent a deux ligne de rayon donne
//===============================================
//========================================================================
// On initialise WellDone a false.                                       +
// On recupere les deux lignes L1 et L2.                                 +
// On sort en erreur dans les cas ou la construction est impossible.     +
// On fait les paralleles a L1 et L2 dans le bon sens.                   +
// On intersecte les paralleles ==> Le point de centre de la solution.   +
// On cree la solution qu on ajoute aux solutions deja trouvees.         +
// On remplit les champs.                                                +
//========================================================================

GccAna_Circ2d2TanRad::
   GccAna_Circ2d2TanRad (const GccEnt_QualifiedLin&  Qualified1 ,
                         const GccEnt_QualifiedLin&  Qualified2 ,
                         const Standard_Real         Radius     ,
                         const Standard_Real
#ifdef DEB
                                                     Tolerance
#endif
                        ):
   qualifier1(1,4) ,
   qualifier2(1,4),
   TheSame1(1,4)   ,
   TheSame2(1,4)   ,
   cirsol(1,4)     ,
   pnttg1sol(1,4)  ,
   pnttg2sol(1,4)  ,
   par1sol(1,4)    ,
   par2sol(1,4)    ,
   pararg1(1,4)    ,
   pararg2(1,4)    
{

  gp_Dir2d dirx(1.0,0.0);
  TColStd_Array1OfReal cote1(1,2);
  TColStd_Array1OfReal cote2(1,2);
  Standard_Integer nbrcote1=0;
  Standard_Integer nbrcote2=0;
  NbrSol = 0;
  WellDone = Standard_False;
  if (!(Qualified1.IsEnclosed() || 
	Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
      !(Qualified2.IsEnclosed() ||
	Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
    GccEnt_BadQualifier::Raise();
    return;
  }
  gp_Lin2d L1 = Qualified1.Qualified();
  gp_Lin2d L2 = Qualified2.Qualified();
  Standard_Real x1dir = (L1.Direction()).X();
  Standard_Real y1dir = (L1.Direction()).Y();
  Standard_Real lx1loc = (L1.Location()).X();
  Standard_Real ly1loc = (L1.Location()).Y();
  Standard_Real x2dir = (L2.Direction()).X();
  Standard_Real y2dir = (L2.Direction()).Y();
  Standard_Real lx2loc = (L2.Location()).X();
  Standard_Real ly2loc = (L2.Location()).Y();
  gp_Pnt2d origin1(lx1loc,ly1loc);
  gp_Pnt2d origin2(lx2loc,ly2loc);
  gp_Dir2d normL1(x1dir,y1dir);
  gp_Dir2d normL2(x2dir,y2dir);
  if (Radius < 0.0) { Standard_NegativeValue::Raise(); }
  else {
    if (L1.Direction().IsParallel(L2.Direction(),Precision::Angular())) { 
      WellDone = Standard_True;
    }
    else {
      if (Qualified1.IsEnclosed() && Qualified2.IsEnclosed()) {
//    =======================================================
	nbrcote1 = 1;
	nbrcote2 = 1;
	cote1(1) = 1.0;
	cote2(1) = 1.0;
      }
      else if(Qualified1.IsEnclosed() && Qualified2.IsOutside()) {
//    ==========================================================
	nbrcote1 = 1;
	nbrcote2 = 1;
	cote1(1) = 1.0;
	cote2(1) = -1.0;
      }
      else if (Qualified1.IsOutside() && Qualified2.IsEnclosed()) {
//    ===========================================================
	nbrcote1 = 1;
	nbrcote2 = 1;
	cote1(1) = -1.0;
	cote2(1) = 1.0;
      }
      else if(Qualified1.IsOutside() && Qualified2.IsOutside()) {
//    =========================================================
	nbrcote1 = 1;
	nbrcote2 = 1;
	cote1(1) = -1.0;
	cote2(1) = -1.0;
      }
      if(Qualified1.IsEnclosed() && Qualified2.IsUnqualified()) {
//    =========================================================
	nbrcote1 = 1;
	nbrcote2 = 2;
	cote1(1) = 1.0;
	cote2(1) = 1.0;
	cote2(2) = -1.0;
      }
      if(Qualified1.IsUnqualified() && Qualified2.IsEnclosed()) {
//    =========================================================
	nbrcote1 = 2;
	nbrcote2 = 1;
	cote1(1) = 1.0;
	cote1(2) = -1.0;
	cote2(1) = 1.0;
      }
      else if(Qualified1.IsOutside() && Qualified2.IsUnqualified()) {
//    =============================================================
	nbrcote1 = 1;
	nbrcote2 = 2;
	cote1(1) = -1.0;
	cote2(1) = 1.0;
	cote2(2) = -1.0;
      }
      if(Qualified1.IsUnqualified() && Qualified2.IsOutside()) {
//    ========================================================
	nbrcote1 = 2;
	nbrcote2 = 1;
	cote1(1) = 1.0;
	cote1(2) = -1.0;
	cote2(1) = -1.0;
      }
      else if(Qualified1.IsUnqualified() && Qualified2.IsUnqualified()) {
//    =================================================================
	nbrcote1 = 2;
	nbrcote2 = 2;
	cote1(1) = 1.0;
	cote1(2) = -1.0;
	cote2(1) = 1.0;
	cote2(2) = -1.0;
      }
      for (Standard_Integer jcote1 = 1 ; jcote1 <= nbrcote1 ; jcote1++) {
	for (Standard_Integer jcote2 = 1 ; jcote2 <= nbrcote2 ; jcote2++) {
	  gp_Lin2d linint1(gp_Pnt2d(lx1loc-cote1(jcote1)*y1dir*Radius,
				    ly1loc+cote1(jcote1)*x1dir*Radius),
			   L1.Direction());
	  gp_Lin2d linint2(gp_Pnt2d(lx2loc-cote2(jcote2)*y2dir*Radius,
				    ly2loc+cote2(jcote2)*x2dir*Radius),
			   L2.Direction());
	  IntAna2d_AnaIntersection Intp(linint1,linint2);
	  if (Intp.IsDone()) {
	    if (!Intp.IsEmpty()) {
	      for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
		NbrSol++;
		gp_Pnt2d Center(Intp.Point(i).Value());
		cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
//              =======================================================
		gp_Dir2d dc1(origin1.XY()-Center.XY());
		gp_Dir2d dc2(origin2.XY()-Center.XY());
		if (!Qualified1.IsUnqualified()) { 
		  qualifier1(NbrSol) = Qualified1.Qualifier();
		}
		else if (dc1.Dot(normL1) > 0.0) {
		  qualifier1(NbrSol) = GccEnt_outside;
		}
		else { qualifier1(NbrSol) = GccEnt_enclosed; }
		if (!Qualified2.IsUnqualified()) { 
		  qualifier2(NbrSol) = Qualified2.Qualifier();
		}
		else if (dc2.Dot(normL2) > 0.0) {
		  qualifier2(NbrSol) = GccEnt_outside;
		}
		else { qualifier2(NbrSol) = GccEnt_enclosed; }
		TheSame1(NbrSol) = 0;
		TheSame2(NbrSol) = 0;
		pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+
				     cote1(jcote1)*Radius*gp_XY(y1dir,-x1dir));
		pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+
				     cote2(jcote2)*Radius*gp_XY(y2dir,-x2dir));
	      }
	    }
	    WellDone = Standard_True;
	  }
	}
      }
    }
  }
  for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
    par1sol(i)=ElCLib::Parameter(cirsol(i),pnttg1sol(i));
    pararg1(i)=ElCLib::Parameter(L1,pnttg1sol(i));
    par2sol(i)=ElCLib::Parameter(cirsol(i),pnttg2sol(i));
    pararg2(i)=ElCLib::Parameter(L2,pnttg2sol(i));
  }
}