Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 | 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 3 | // |
973c2be1 | 4 | // This file is part of Open CASCADE Technology software library. |
b311480e | 5 | // |
d5f74e42 | 6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
10 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 11 | // |
973c2be1 | 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. | |
7fd59977 | 14 | |
15 | #include <GccAna_Circ2dTanOnRad.jxx> | |
16 | ||
17 | #include <ElCLib.hxx> | |
18 | #include <IntAna2d_AnaIntersection.hxx> | |
19 | #include <IntAna2d_IntPoint.hxx> | |
20 | #include <Standard_NegativeValue.hxx> | |
21 | #include <Standard_OutOfRange.hxx> | |
22 | #include <gp_Dir2d.hxx> | |
23 | #include <GccEnt_BadQualifier.hxx> | |
24 | ||
25 | //========================================================================= | |
0d969553 Y |
26 | // Circle tangent to straight line Qualified1 (L1). + |
27 | // center on circle OnCirc. + | |
28 | // with radius Radius. + | |
7fd59977 | 29 | // + |
0d969553 Y |
30 | // Initialize table of solutions cirsol and all fields. + |
31 | // Eliminate cases not being the solution. + | |
32 | // Create parallel line(s) to L1 in the required direction(s). + | |
33 | // Intersect parallel line(s) with OnCirc and obtain + | |
34 | // center points of found solutions. + | |
35 | // Create solutions cirsol. + | |
7fd59977 | 36 | //========================================================================= |
37 | ||
38 | GccAna_Circ2dTanOnRad:: | |
39 | GccAna_Circ2dTanOnRad (const GccEnt_QualifiedLin& Qualified1, | |
40 | const gp_Circ2d& OnCirc , | |
41 | const Standard_Real Radius , | |
42 | const Standard_Real Tolerance ): | |
43 | ||
44 | //========================================================================= | |
0d969553 | 45 | // Initialization of fields. + |
7fd59977 | 46 | //========================================================================= |
47 | ||
48 | cirsol(1,4) , | |
49 | qualifier1(1,4) , | |
50 | TheSame1(1,4) , | |
51 | pnttg1sol(1,4), | |
52 | pntcen3(1,4) , | |
53 | par1sol(1,4) , | |
54 | pararg1(1,4) , | |
55 | parcen3(1,4) | |
56 | { | |
57 | ||
58 | TheSame1.Init(0); | |
59 | gp_Dir2d dirx(1.0,0.0); | |
60 | Standard_Real Tol = Abs(Tolerance); | |
61 | WellDone = Standard_False; | |
62 | NbrSol = 0; | |
63 | if (!(Qualified1.IsEnclosed() || | |
64 | Qualified1.IsOutside() || Qualified1.IsUnqualified())) { | |
65 | GccEnt_BadQualifier::Raise(); | |
66 | return; | |
67 | } | |
68 | ||
69 | //========================================================================= | |
0d969553 | 70 | // Initialisation of various variables. + |
7fd59977 | 71 | //========================================================================= |
72 | ||
73 | Standard_Integer nbsol = 0; | |
74 | Standard_Integer sign = 0; | |
75 | gp_Lin2d L1 = Qualified1.Qualified(); | |
76 | gp_Pnt2d origin1(L1.Location()); | |
77 | gp_Dir2d dir1(L1.Direction()); | |
78 | gp_Dir2d normL1(-dir1.Y(),dir1.X()); | |
79 | Standard_Real dist1 = L1.Distance(OnCirc.Location())-OnCirc.Radius(); | |
80 | Standard_Real dist2 = L1.Distance(OnCirc.Location())+OnCirc.Radius(); | |
81 | ||
82 | //========================================================================= | |
0d969553 | 83 | // Processing. + |
7fd59977 | 84 | //========================================================================= |
85 | ||
86 | if (Radius < 0.0) { Standard_NegativeValue::Raise(); } | |
87 | else { | |
88 | L1 = Qualified1.Qualified(); | |
89 | if ((dist1-Radius>Tol) || (Tol<Radius-dist2)) { WellDone=Standard_True; } | |
90 | else { | |
91 | ||
0d969553 | 92 | // to modify later |
7fd59977 | 93 | |
94 | if (dist1-Radius > 0.0) { dist1 = Radius; } | |
95 | else if (dist2-Radius < 0.0) { dist2 = Radius; } | |
96 | ||
97 | if (Qualified1.IsEnclosed()) { | |
98 | // ============================ | |
99 | nbsol = 1; | |
100 | sign = -1; | |
101 | } | |
102 | else if (Qualified1.IsOutside()) { | |
103 | // ================================ | |
104 | nbsol = 1; | |
105 | sign = 1; | |
106 | } | |
107 | else { | |
108 | // ==== | |
109 | nbsol = 2; | |
110 | sign = 1; | |
111 | } | |
112 | for (Standard_Integer j = 1 ; j <= nbsol ;j++) { | |
113 | sign = -sign; | |
114 | gp_Lin2d L(gp_Pnt2d(origin1.X()-sign*Radius*dir1.Y(), | |
115 | origin1.Y()+sign*Radius*dir1.X()),dir1); | |
116 | IntAna2d_AnaIntersection Intp(L,OnCirc); | |
117 | if (Intp.IsDone()) { | |
118 | if (!Intp.IsEmpty()) { | |
119 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
120 | NbrSol++; | |
121 | gp_Pnt2d Center(Intp.Point(i).Value()); | |
122 | gp_Ax2d axe(Center,dirx); | |
123 | cirsol(NbrSol) = gp_Circ2d(axe,Radius); | |
124 | // ====================================== | |
125 | gp_Dir2d dc1(origin1.XY()-Center.XY()); | |
126 | sign = (Standard_Integer) dc1.Dot(normL1); | |
127 | if (!Qualified1.IsUnqualified()) { | |
128 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
129 | } | |
130 | else if (dc1.Dot(normL1) > 0.0) { | |
131 | qualifier1(NbrSol) = GccEnt_outside; | |
132 | } | |
133 | else { qualifier1(NbrSol) = GccEnt_enclosed; } | |
134 | pntcen3(NbrSol) = cirsol(NbrSol).Location(); | |
135 | pnttg1sol(NbrSol) = gp_Pnt2d(pntcen3(NbrSol).XY()+ | |
136 | gp_XY(sign*Radius*dir1.Y(), | |
137 | -sign*Radius*dir1.X())); | |
138 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); | |
139 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
140 | pnttg1sol(NbrSol)); | |
141 | parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen3(NbrSol)); | |
142 | } | |
143 | } | |
144 | WellDone = Standard_True; | |
145 | } | |
146 | } | |
147 | } | |
148 | } | |
149 | } | |
150 | ||
151 | ||
152 |