Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1992-01-02 |
2 | // Created by: Remi GILET | |
3 | // Copyright (c) 1992-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
973c2be1 | 8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
17 | #include <GccAna_Circ2d2TanOn.jxx> | |
18 | ||
19 | #include <ElCLib.hxx> | |
20 | #include <gp_Dir2d.hxx> | |
21 | #include <gp_Ax2d.hxx> | |
22 | #include <IntAna2d_AnaIntersection.hxx> | |
23 | #include <IntAna2d_IntPoint.hxx> | |
24 | #include <GccAna_LinPnt2dBisec.hxx> | |
25 | #include <GccInt_IType.hxx> | |
26 | #include <GccInt_Bisec.hxx> | |
27 | #include <GccInt_BLine.hxx> | |
28 | #include <IntAna2d_Conic.hxx> | |
29 | #include <GccEnt_BadQualifier.hxx> | |
30 | ||
31 | //========================================================================= | |
0d969553 Y |
32 | // Creation of a circle tangent to straight line L1 and a point Point2. + |
33 | // centered on a circle. + | |
34 | // We start by making difference between boundary cases that will be + | |
35 | // processed separately. + | |
36 | // In general case: + | |
7fd59977 | 37 | // ==================== + |
0d969553 Y |
38 | // We calculate bissectrices to L1 and Point2 that give us all + |
39 | // all possible locations of centers of all circles + | |
40 | // tangent to L1 and Point2. + | |
41 | // We intersect these bissectrices with circle OnCirc which gives us + | |
42 | // points among which we'll choose the solutions. + | |
43 | // The choice is made using Qualifiers of L1. + | |
7fd59977 | 44 | //========================================================================= |
45 | ||
b311480e | 46 | GccAna_Circ2d2TanOn:: |
7fd59977 | 47 | GccAna_Circ2d2TanOn (const GccEnt_QualifiedLin& Qualified1 , |
48 | const gp_Pnt2d& Point2 , | |
49 | const gp_Circ2d& OnCirc , | |
50 | const Standard_Real Tolerance ): | |
51 | cirsol(1,4) , | |
52 | qualifier1(1,4) , | |
53 | qualifier2(1,4) , | |
54 | TheSame1(1,4) , | |
55 | TheSame2(1,4) , | |
56 | pnttg1sol(1,4) , | |
57 | pnttg2sol(1,4) , | |
58 | pntcen(1,4) , | |
59 | par1sol(1,4) , | |
60 | par2sol(1,4) , | |
61 | pararg1(1,4) , | |
62 | pararg2(1,4) , | |
63 | parcen3(1,4) | |
64 | { | |
65 | ||
66 | TheSame1.Init(0); | |
67 | TheSame2.Init(0); | |
68 | WellDone = Standard_False; | |
69 | NbrSol = 0; | |
70 | if (!(Qualified1.IsEnclosed() || | |
71 | Qualified1.IsOutside() || Qualified1.IsUnqualified())) { | |
72 | GccEnt_BadQualifier::Raise(); | |
73 | return; | |
74 | } | |
75 | Standard_Real Tol = Abs(Tolerance); | |
76 | gp_Dir2d dirx(1.,0.); | |
77 | gp_Lin2d L1 = Qualified1.Qualified(); | |
78 | gp_Pnt2d originL1(L1.Location()); | |
79 | gp_Dir2d dirL1(L1.Direction()); | |
80 | gp_Dir2d normL1(-dirL1.Y(),dirL1.X()); | |
81 | ||
82 | //========================================================================= | |
0d969553 | 83 | // Processing of boundary cases. + |
7fd59977 | 84 | //========================================================================= |
85 | ||
86 | Standard_Real Ron = OnCirc.Radius(); | |
87 | Standard_Real distpc = OnCirc.Location().Distance(Point2); | |
88 | gp_Dir2d dir(OnCirc.Location().XY()-Point2.XY()); | |
89 | gp_Pnt2d pinterm(Point2.XY()+(distpc+Ron)*dir.XY()); | |
90 | Standard_Real dist1 = L1.Distance(pinterm); | |
6e6cd5d9 | 91 | |
7fd59977 | 92 | if (Abs(dist1-distpc+Ron) <= Tol) { |
93 | dir = gp_Dir2d(-dirL1.Y(),dirL1.X()); | |
94 | gp_Dir2d direc(originL1.XY()-pinterm.XY()); | |
95 | if (Qualified1.IsOutside()) { | |
96 | if (direc.Dot(dir) >= 0.0) { WellDone = Standard_True; } | |
97 | } | |
98 | else if (Qualified1.IsEnclosed()) { | |
99 | if (direc.Dot(dir) <= 0.0) { WellDone = Standard_True; } | |
100 | } | |
101 | else { WellDone = Standard_True; } | |
102 | if (WellDone) { | |
103 | NbrSol++; | |
104 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),dist1); | |
105 | // ======================================================= | |
106 | gp_Dir2d dc1(originL1.XY()-pinterm.XY()); | |
107 | Standard_Real sign = dc1.Dot(normL1); | |
108 | if (!Qualified1.IsUnqualified()) { | |
109 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
110 | } | |
111 | else if (dc1.Dot(normL1) > 0.0) { qualifier1(NbrSol) = GccEnt_outside; } | |
112 | else { qualifier1(NbrSol) = GccEnt_enclosed; } | |
113 | qualifier2(NbrSol) = GccEnt_noqualifier; | |
114 | dc1 = gp_Dir2d(sign*gp_XY(-dirL1.Y(),dirL1.X())); | |
115 | pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dist1*dc1.XY()); | |
116 | par1sol(NbrSol) = ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol)); | |
117 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); | |
118 | pntcen(NbrSol) = pinterm; | |
119 | parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol)); | |
120 | parcen3(NbrSol) = 0.; | |
121 | pnttg2sol(NbrSol) = Point2; | |
122 | pararg2(NbrSol) = 0.; | |
123 | par2sol(NbrSol) = ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol)); | |
124 | return; | |
125 | } | |
126 | } | |
127 | ||
128 | //========================================================================= | |
0d969553 | 129 | // General case. + |
7fd59977 | 130 | //========================================================================= |
131 | ||
132 | GccAna_LinPnt2dBisec Bis(L1,Point2); | |
133 | if (Bis.IsDone()) { | |
134 | Handle(GccInt_Bisec) Sol = Bis.ThisSolution(); | |
135 | GccInt_IType type = Sol->ArcType(); | |
136 | IntAna2d_AnaIntersection Intp; | |
137 | if (type == GccInt_Lin) { | |
138 | Intp.Perform(Sol->Line(),OnCirc); | |
139 | } | |
140 | if (type == GccInt_Par) { | |
141 | Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Parabola())); | |
142 | } | |
143 | if (Intp.IsDone()) { | |
144 | if (!Intp.IsEmpty()) { | |
145 | for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) { | |
146 | gp_Pnt2d Center(Intp.Point(j).Value()); | |
147 | Standard_Real Radius = L1.Distance(Center); | |
148 | // Standard_Integer nbsol = 1; | |
149 | Standard_Boolean ok = Standard_False; | |
150 | if (Qualified1.IsEnclosed()) { | |
151 | if ((((originL1.X()-Center.X())*(-dirL1.Y()))+ | |
152 | ((originL1.Y()-Center.Y())*(dirL1.X())))<=0){ | |
153 | ok = Standard_True; | |
154 | } | |
155 | } | |
156 | else if (Qualified1.IsOutside()) { | |
157 | if ((((originL1.X()-Center.X())*(-dirL1.Y()))+ | |
158 | ((originL1.Y()-Center.Y())*(dirL1.X())))>=0){ | |
159 | ok = Standard_True; | |
160 | } | |
161 | } | |
162 | else if (Qualified1.IsUnqualified()) { | |
163 | ok = Standard_True; | |
164 | } | |
165 | if (ok) { | |
166 | NbrSol++; | |
167 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius); | |
168 | // ======================================================= | |
169 | TheSame1(NbrSol) = 0; | |
170 | TheSame2(NbrSol) = 0; | |
171 | gp_Dir2d dc1(originL1.XY()-Center.XY()); | |
172 | Standard_Real sign = dc1.Dot(normL1); | |
173 | if (!Qualified1.IsUnqualified()) { | |
174 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
175 | } | |
176 | else if (dc1.Dot(normL1) > 0.0) { | |
177 | qualifier1(NbrSol) = GccEnt_outside; | |
178 | } | |
179 | else { qualifier1(NbrSol) = GccEnt_enclosed; } | |
180 | qualifier2(NbrSol) = GccEnt_noqualifier; | |
181 | dc1=gp_Dir2d(sign*gp_XY(-dirL1.Y(),dirL1.X())); | |
182 | pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+dist1*dc1.XY()); | |
183 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
184 | pnttg1sol(NbrSol)); | |
185 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); | |
186 | pntcen(NbrSol) = Center; | |
187 | parcen3(NbrSol) = ElCLib::Parameter(OnCirc,pntcen(NbrSol)); | |
188 | pnttg2sol(NbrSol) = Point2; | |
189 | pararg2(NbrSol) = 0.; | |
190 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
191 | pnttg2sol(NbrSol)); | |
192 | qualifier2(NbrSol) = GccEnt_noqualifier; | |
193 | } | |
194 | } | |
195 | } | |
196 | WellDone = Standard_True; | |
197 | } | |
198 | } | |
199 | } | |
200 |