Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // file GccAna_Circ2dTanOnRad_4.cxx, REG 08/07/91 |
2 | ||
3 | #include <GccAna_Circ2dTanOnRad.jxx> | |
4 | ||
5 | #include <ElCLib.hxx> | |
6 | #include <IntAna2d_AnaIntersection.hxx> | |
7 | #include <IntAna2d_IntPoint.hxx> | |
8 | #include <Standard_NegativeValue.hxx> | |
9 | #include <Standard_OutOfRange.hxx> | |
10 | #include <gp_Dir2d.hxx> | |
11 | #include <GccEnt_BadQualifier.hxx> | |
12 | ||
13 | //========================================================================= | |
0d969553 Y |
14 | // Circle tangent to straight line Qualified1 (L1). + |
15 | // center on circle OnCirc. + | |
16 | // with radius Radius. + | |
7fd59977 | 17 | // + |
0d969553 Y |
18 | // Initialize table of solutions cirsol and all fields. + |
19 | // Eliminate cases not being the solution. + | |
20 | // Create parallel line(s) to L1 in the required direction(s). + | |
21 | // Intersect parallel line(s) with OnCirc and obtain + | |
22 | // center points of found solutions. + | |
23 | // Create solutions cirsol. + | |
7fd59977 | 24 | //========================================================================= |
25 | ||
26 | GccAna_Circ2dTanOnRad:: | |
27 | GccAna_Circ2dTanOnRad (const GccEnt_QualifiedLin& Qualified1, | |
28 | const gp_Circ2d& OnCirc , | |
29 | const Standard_Real Radius , | |
30 | const Standard_Real Tolerance ): | |
31 | ||
32 | //========================================================================= | |
0d969553 | 33 | // Initialization of fields. + |
7fd59977 | 34 | //========================================================================= |
35 | ||
36 | cirsol(1,4) , | |
37 | qualifier1(1,4) , | |
38 | TheSame1(1,4) , | |
39 | pnttg1sol(1,4), | |
40 | pntcen3(1,4) , | |
41 | par1sol(1,4) , | |
42 | pararg1(1,4) , | |
43 | parcen3(1,4) | |
44 | { | |
45 | ||
46 | TheSame1.Init(0); | |
47 | gp_Dir2d dirx(1.0,0.0); | |
48 | Standard_Real Tol = Abs(Tolerance); | |
49 | WellDone = Standard_False; | |
50 | NbrSol = 0; | |
51 | if (!(Qualified1.IsEnclosed() || | |
52 | Qualified1.IsOutside() || Qualified1.IsUnqualified())) { | |
53 | GccEnt_BadQualifier::Raise(); | |
54 | return; | |
55 | } | |
56 | ||
57 | //========================================================================= | |
0d969553 | 58 | // Initialisation of various variables. + |
7fd59977 | 59 | //========================================================================= |
60 | ||
61 | Standard_Integer nbsol = 0; | |
62 | Standard_Integer sign = 0; | |
63 | gp_Lin2d L1 = Qualified1.Qualified(); | |
64 | gp_Pnt2d origin1(L1.Location()); | |
65 | gp_Dir2d dir1(L1.Direction()); | |
66 | gp_Dir2d normL1(-dir1.Y(),dir1.X()); | |
67 | Standard_Real dist1 = L1.Distance(OnCirc.Location())-OnCirc.Radius(); | |
68 | Standard_Real dist2 = L1.Distance(OnCirc.Location())+OnCirc.Radius(); | |
69 | ||
70 | //========================================================================= | |
0d969553 | 71 | // Processing. + |
7fd59977 | 72 | //========================================================================= |
73 | ||
74 | if (Radius < 0.0) { Standard_NegativeValue::Raise(); } | |
75 | else { | |
76 | L1 = Qualified1.Qualified(); | |
77 | if ((dist1-Radius>Tol) || (Tol<Radius-dist2)) { WellDone=Standard_True; } | |
78 | else { | |
79 | ||
0d969553 | 80 | // to modify later |
7fd59977 | 81 | |
82 | if (dist1-Radius > 0.0) { dist1 = Radius; } | |
83 | else if (dist2-Radius < 0.0) { dist2 = Radius; } | |
84 | ||
85 | if (Qualified1.IsEnclosed()) { | |
86 | // ============================ | |
87 | nbsol = 1; | |
88 | sign = -1; | |
89 | } | |
90 | else if (Qualified1.IsOutside()) { | |
91 | // ================================ | |
92 | nbsol = 1; | |
93 | sign = 1; | |
94 | } | |
95 | else { | |
96 | // ==== | |
97 | nbsol = 2; | |
98 | sign = 1; | |
99 | } | |
100 | for (Standard_Integer j = 1 ; j <= nbsol ;j++) { | |
101 | sign = -sign; | |
102 | gp_Lin2d L(gp_Pnt2d(origin1.X()-sign*Radius*dir1.Y(), | |
103 | origin1.Y()+sign*Radius*dir1.X()),dir1); | |
104 | IntAna2d_AnaIntersection Intp(L,OnCirc); | |
105 | if (Intp.IsDone()) { | |
106 | if (!Intp.IsEmpty()) { | |
107 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
108 | NbrSol++; | |
109 | gp_Pnt2d Center(Intp.Point(i).Value()); | |
110 | gp_Ax2d axe(Center,dirx); | |
111 | cirsol(NbrSol) = gp_Circ2d(axe,Radius); | |
112 | // ====================================== | |
113 | gp_Dir2d dc1(origin1.XY()-Center.XY()); | |
114 | sign = (Standard_Integer) dc1.Dot(normL1); | |
115 | if (!Qualified1.IsUnqualified()) { | |
116 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
117 | } | |
118 | else if (dc1.Dot(normL1) > 0.0) { | |
119 | qualifier1(NbrSol) = GccEnt_outside; | |
120 | } | |
121 | else { qualifier1(NbrSol) = GccEnt_enclosed; } | |
122 | pntcen3(NbrSol) = cirsol(NbrSol).Location(); | |
123 | pnttg1sol(NbrSol) = gp_Pnt2d(pntcen3(NbrSol).XY()+ | |
124 | gp_XY(sign*Radius*dir1.Y(), | |
125 | -sign*Radius*dir1.X())); | |
126 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); | |
127 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
128 | pnttg1sol(NbrSol)); | |
129 | parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen3(NbrSol)); | |
130 | } | |
131 | } | |
132 | WellDone = Standard_True; | |
133 | } | |
134 | } | |
135 | } | |
136 | } | |
137 | } | |
138 | ||
139 | ||
140 |