1 // Created on: 1991-09-24
2 // Created by: Remi GILET
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <GccAna_Circ2d2TanRad.hxx>
20 #include <GccEnt_BadQualifier.hxx>
21 #include <GccEnt_QualifiedLin.hxx>
22 #include <gp_Ax2d.hxx>
23 #include <gp_Circ2d.hxx>
24 #include <gp_Lin2d.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <IntAna2d_AnaIntersection.hxx>
27 #include <IntAna2d_IntPoint.hxx>
28 #include <Precision.hxx>
29 #include <Standard_NegativeValue.hxx>
30 #include <TColStd_Array1OfReal.hxx>
32 // circular tangent to two lines of given radius
33 //===============================================
34 //========================================================================
35 // Initialize WellDone to false. +
36 // Return two lines L1 and L2. +
37 // Leave with error if the construction is impossible. +
38 // Create parallel lines to L1 and L2 in the proper direction. +
39 // Intersect parallels ==> The center point of the solution. +
40 // Create the solution to be added to the already found solutions. +
42 //========================================================================
43 GccAna_Circ2d2TanRad::
44 GccAna_Circ2d2TanRad (const GccEnt_QualifiedLin& Qualified1 ,
45 const GccEnt_QualifiedLin& Qualified2 ,
46 const Standard_Real Radius ,
47 const Standard_Real ):
61 gp_Dir2d dirx(1.0,0.0);
62 TColStd_Array1OfReal cote1(1,2);
63 TColStd_Array1OfReal cote2(1,2);
64 Standard_Integer nbrcote1=0;
65 Standard_Integer nbrcote2=0;
67 WellDone = Standard_False;
68 if (!(Qualified1.IsEnclosed() ||
69 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
70 !(Qualified2.IsEnclosed() ||
71 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
72 throw GccEnt_BadQualifier();
75 gp_Lin2d L1 = Qualified1.Qualified();
76 gp_Lin2d L2 = Qualified2.Qualified();
77 Standard_Real x1dir = (L1.Direction()).X();
78 Standard_Real y1dir = (L1.Direction()).Y();
79 Standard_Real lx1loc = (L1.Location()).X();
80 Standard_Real ly1loc = (L1.Location()).Y();
81 Standard_Real x2dir = (L2.Direction()).X();
82 Standard_Real y2dir = (L2.Direction()).Y();
83 Standard_Real lx2loc = (L2.Location()).X();
84 Standard_Real ly2loc = (L2.Location()).Y();
85 gp_Pnt2d origin1(lx1loc,ly1loc);
86 gp_Pnt2d origin2(lx2loc,ly2loc);
87 gp_Dir2d normL1(x1dir,y1dir);
88 gp_Dir2d normL2(x2dir,y2dir);
89 if (Radius < 0.0) { throw Standard_NegativeValue(); }
91 if (L1.Direction().IsParallel(L2.Direction(),Precision::Angular())) {
92 WellDone = Standard_True;
95 if (Qualified1.IsEnclosed() && Qualified2.IsEnclosed()) {
96 // =======================================================
102 else if(Qualified1.IsEnclosed() && Qualified2.IsOutside()) {
103 // ==========================================================
109 else if (Qualified1.IsOutside() && Qualified2.IsEnclosed()) {
110 // ===========================================================
116 else if(Qualified1.IsOutside() && Qualified2.IsOutside()) {
117 // =========================================================
123 if(Qualified1.IsEnclosed() && Qualified2.IsUnqualified()) {
124 // =========================================================
131 if(Qualified1.IsUnqualified() && Qualified2.IsEnclosed()) {
132 // =========================================================
139 else if(Qualified1.IsOutside() && Qualified2.IsUnqualified()) {
140 // =============================================================
147 if(Qualified1.IsUnqualified() && Qualified2.IsOutside()) {
148 // ========================================================
155 else if(Qualified1.IsUnqualified() && Qualified2.IsUnqualified()) {
156 // =================================================================
164 for (Standard_Integer jcote1 = 1 ; jcote1 <= nbrcote1 ; jcote1++) {
165 for (Standard_Integer jcote2 = 1 ; jcote2 <= nbrcote2 ; jcote2++) {
166 gp_Lin2d linint1(gp_Pnt2d(lx1loc-cote1(jcote1)*y1dir*Radius,
167 ly1loc+cote1(jcote1)*x1dir*Radius),
169 gp_Lin2d linint2(gp_Pnt2d(lx2loc-cote2(jcote2)*y2dir*Radius,
170 ly2loc+cote2(jcote2)*x2dir*Radius),
172 IntAna2d_AnaIntersection Intp(linint1,linint2);
174 if (!Intp.IsEmpty()) {
175 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
177 gp_Pnt2d Center(Intp.Point(i).Value());
178 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
179 // =======================================================
180 gp_Dir2d dc1(origin1.XY()-Center.XY());
181 gp_Dir2d dc2(origin2.XY()-Center.XY());
182 if (!Qualified1.IsUnqualified()) {
183 qualifier1(NbrSol) = Qualified1.Qualifier();
185 else if (dc1.Dot(normL1) > 0.0) {
186 qualifier1(NbrSol) = GccEnt_outside;
188 else { qualifier1(NbrSol) = GccEnt_enclosed; }
189 if (!Qualified2.IsUnqualified()) {
190 qualifier2(NbrSol) = Qualified2.Qualifier();
192 else if (dc2.Dot(normL2) > 0.0) {
193 qualifier2(NbrSol) = GccEnt_outside;
195 else { qualifier2(NbrSol) = GccEnt_enclosed; }
196 TheSame1(NbrSol) = 0;
197 TheSame2(NbrSol) = 0;
198 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+
199 cote1(jcote1)*Radius*gp_XY(y1dir,-x1dir));
200 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+
201 cote2(jcote2)*Radius*gp_XY(y2dir,-x2dir));
204 WellDone = Standard_True;
210 for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
211 par1sol(i)=ElCLib::Parameter(cirsol(i),pnttg1sol(i));
212 pararg1(i)=ElCLib::Parameter(L1,pnttg1sol(i));
213 par2sol(i)=ElCLib::Parameter(cirsol(i),pnttg2sol(i));
214 pararg2(i)=ElCLib::Parameter(L2,pnttg2sol(i));