1 // File: GccAna_Circ2d2TanRad_4.cxx
2 // Created: Tue Sep 24 09:15:20 1991
6 #include <GccAna_Circ2d2TanRad.jxx>
9 #include <gp_Circ2d.hxx>
10 #include <gp_Lin2d.hxx>
11 #include <gp_Ax2d.hxx>
12 #include <IntAna2d_AnaIntersection.hxx>
13 #include <IntAna2d_IntPoint.hxx>
14 #include <TColStd_Array1OfReal.hxx>
15 #include <Standard_NegativeValue.hxx>
17 #include <GccEnt_BadQualifier.hxx>
19 #include <Precision.hxx>
21 // circular tangent to two lines of given radius
22 //===============================================
23 //========================================================================
24 // Initialize WellDone to false. +
25 // Return two lines L1 and L2. +
26 // Leave with error if the construction is impossible. +
27 // Create parallel lines to L1 and L2 in the proper direction. +
28 // Intersect parallels ==> The center point of the solution. +
29 // Create the solution to be added to the already found solutions. +
31 //========================================================================
33 GccAna_Circ2d2TanRad::
34 GccAna_Circ2d2TanRad (const GccEnt_QualifiedLin& Qualified1 ,
35 const GccEnt_QualifiedLin& Qualified2 ,
36 const Standard_Real Radius ,
55 gp_Dir2d dirx(1.0,0.0);
56 TColStd_Array1OfReal cote1(1,2);
57 TColStd_Array1OfReal cote2(1,2);
58 Standard_Integer nbrcote1=0;
59 Standard_Integer nbrcote2=0;
61 WellDone = Standard_False;
62 if (!(Qualified1.IsEnclosed() ||
63 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
64 !(Qualified2.IsEnclosed() ||
65 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
66 GccEnt_BadQualifier::Raise();
69 gp_Lin2d L1 = Qualified1.Qualified();
70 gp_Lin2d L2 = Qualified2.Qualified();
71 Standard_Real x1dir = (L1.Direction()).X();
72 Standard_Real y1dir = (L1.Direction()).Y();
73 Standard_Real lx1loc = (L1.Location()).X();
74 Standard_Real ly1loc = (L1.Location()).Y();
75 Standard_Real x2dir = (L2.Direction()).X();
76 Standard_Real y2dir = (L2.Direction()).Y();
77 Standard_Real lx2loc = (L2.Location()).X();
78 Standard_Real ly2loc = (L2.Location()).Y();
79 gp_Pnt2d origin1(lx1loc,ly1loc);
80 gp_Pnt2d origin2(lx2loc,ly2loc);
81 gp_Dir2d normL1(x1dir,y1dir);
82 gp_Dir2d normL2(x2dir,y2dir);
83 if (Radius < 0.0) { Standard_NegativeValue::Raise(); }
85 if (L1.Direction().IsParallel(L2.Direction(),Precision::Angular())) {
86 WellDone = Standard_True;
89 if (Qualified1.IsEnclosed() && Qualified2.IsEnclosed()) {
90 // =======================================================
96 else if(Qualified1.IsEnclosed() && Qualified2.IsOutside()) {
97 // ==========================================================
103 else if (Qualified1.IsOutside() && Qualified2.IsEnclosed()) {
104 // ===========================================================
110 else if(Qualified1.IsOutside() && Qualified2.IsOutside()) {
111 // =========================================================
117 if(Qualified1.IsEnclosed() && Qualified2.IsUnqualified()) {
118 // =========================================================
125 if(Qualified1.IsUnqualified() && Qualified2.IsEnclosed()) {
126 // =========================================================
133 else if(Qualified1.IsOutside() && Qualified2.IsUnqualified()) {
134 // =============================================================
141 if(Qualified1.IsUnqualified() && Qualified2.IsOutside()) {
142 // ========================================================
149 else if(Qualified1.IsUnqualified() && Qualified2.IsUnqualified()) {
150 // =================================================================
158 for (Standard_Integer jcote1 = 1 ; jcote1 <= nbrcote1 ; jcote1++) {
159 for (Standard_Integer jcote2 = 1 ; jcote2 <= nbrcote2 ; jcote2++) {
160 gp_Lin2d linint1(gp_Pnt2d(lx1loc-cote1(jcote1)*y1dir*Radius,
161 ly1loc+cote1(jcote1)*x1dir*Radius),
163 gp_Lin2d linint2(gp_Pnt2d(lx2loc-cote2(jcote2)*y2dir*Radius,
164 ly2loc+cote2(jcote2)*x2dir*Radius),
166 IntAna2d_AnaIntersection Intp(linint1,linint2);
168 if (!Intp.IsEmpty()) {
169 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
171 gp_Pnt2d Center(Intp.Point(i).Value());
172 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
173 // =======================================================
174 gp_Dir2d dc1(origin1.XY()-Center.XY());
175 gp_Dir2d dc2(origin2.XY()-Center.XY());
176 if (!Qualified1.IsUnqualified()) {
177 qualifier1(NbrSol) = Qualified1.Qualifier();
179 else if (dc1.Dot(normL1) > 0.0) {
180 qualifier1(NbrSol) = GccEnt_outside;
182 else { qualifier1(NbrSol) = GccEnt_enclosed; }
183 if (!Qualified2.IsUnqualified()) {
184 qualifier2(NbrSol) = Qualified2.Qualifier();
186 else if (dc2.Dot(normL2) > 0.0) {
187 qualifier2(NbrSol) = GccEnt_outside;
189 else { qualifier2(NbrSol) = GccEnt_enclosed; }
190 TheSame1(NbrSol) = 0;
191 TheSame2(NbrSol) = 0;
192 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+
193 cote1(jcote1)*Radius*gp_XY(y1dir,-x1dir));
194 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+
195 cote2(jcote2)*Radius*gp_XY(y2dir,-x2dir));
198 WellDone = Standard_True;
204 for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
205 par1sol(i)=ElCLib::Parameter(cirsol(i),pnttg1sol(i));
206 pararg1(i)=ElCLib::Parameter(L1,pnttg1sol(i));
207 par2sol(i)=ElCLib::Parameter(cirsol(i),pnttg2sol(i));
208 pararg2(i)=ElCLib::Parameter(L2,pnttg2sol(i));