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 | // |
d5f74e42 | 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 | |
973c2be1 | 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 | |
7fd59977 | 17 | |
18 | #include <ElCLib.hxx> | |
42cf5bc1 | 19 | #include <GccAna_Circ2d2TanOn.hxx> |
7fd59977 | 20 | #include <GccAna_LinPnt2dBisec.hxx> |
42cf5bc1 | 21 | #include <GccEnt_BadQualifier.hxx> |
22 | #include <GccEnt_QualifiedCirc.hxx> | |
23 | #include <GccEnt_QualifiedLin.hxx> | |
7fd59977 | 24 | #include <GccInt_BCirc.hxx> |
42cf5bc1 | 25 | #include <GccInt_Bisec.hxx> |
7fd59977 | 26 | #include <GccInt_BLine.hxx> |
42cf5bc1 | 27 | #include <GccInt_IType.hxx> |
28 | #include <gp_Ax2d.hxx> | |
29 | #include <gp_Circ2d.hxx> | |
30 | #include <gp_Dir2d.hxx> | |
31 | #include <gp_Lin2d.hxx> | |
32 | #include <gp_Pnt2d.hxx> | |
33 | #include <IntAna2d_AnaIntersection.hxx> | |
7fd59977 | 34 | #include <IntAna2d_Conic.hxx> |
42cf5bc1 | 35 | #include <IntAna2d_IntPoint.hxx> |
7fd59977 | 36 | #include <Precision.hxx> |
42cf5bc1 | 37 | #include <Standard_OutOfRange.hxx> |
38 | #include <StdFail_NotDone.hxx> | |
39 | ||
7fd59977 | 40 | //========================================================================= |
0d969553 Y |
41 | // Creation of a circle Tangent to : 1 straight line L1. + |
42 | // Passing by : 1 point Point2. + | |
43 | // Centered on : 1 straight line OnLine. + | |
44 | // with a Tolerance of precision : Tolerance. + | |
7fd59977 | 45 | // + |
0d969553 Y |
46 | // We start by making difference with various boundary cases that will be + |
47 | // processed separately. + | |
48 | // For the general case: + | |
7fd59977 | 49 | // ==================== + |
0d969553 Y |
50 | // We calculate bissectrices to L1 and Point2 that give us + |
51 | // all possible locations of centers of all circles + | |
52 | // tangent to L1 and passing through Point2. + | |
53 | // We intersect these bissectrices with straight line OnLine which gives us + | |
54 | // the points among which we'll choose the solutions. + | |
55 | // The choices are made basing on Qualifieurs of L1. + | |
7fd59977 | 56 | //========================================================================= |
7fd59977 | 57 | GccAna_Circ2d2TanOn:: |
58 | GccAna_Circ2d2TanOn (const GccEnt_QualifiedLin& Qualified1 , | |
59 | const gp_Pnt2d& Point2 , | |
60 | const gp_Lin2d& OnLine , | |
61 | const Standard_Real Tolerance ): | |
62 | cirsol(1,4) , | |
63 | qualifier1(1,4) , | |
64 | qualifier2(1,4), | |
65 | TheSame1(1,4) , | |
66 | TheSame2(1,4) , | |
67 | pnttg1sol(1,4) , | |
68 | pnttg2sol(1,4) , | |
69 | pntcen(1,4) , | |
70 | par1sol(1,4) , | |
71 | par2sol(1,4) , | |
72 | pararg1(1,4) , | |
73 | pararg2(1,4) , | |
74 | parcen3(1,4) | |
75 | { | |
76 | TheSame1.Init(0); | |
77 | TheSame2.Init(0); | |
78 | WellDone = Standard_False; | |
79 | NbrSol = 0; | |
80 | if (!(Qualified1.IsEnclosed() || | |
81 | Qualified1.IsOutside() || Qualified1.IsUnqualified())) { | |
9775fa61 | 82 | throw GccEnt_BadQualifier(); |
7fd59977 | 83 | return; |
84 | } | |
85 | Standard_Real Tol = Abs(Tolerance); | |
86 | gp_Dir2d dirx(1.,0.); | |
87 | gp_Lin2d L1 = Qualified1.Qualified(); | |
88 | gp_Pnt2d originL1(L1.Location()); | |
89 | gp_Dir2d dirL1(L1.Direction()); | |
90 | gp_Dir2d normal(-dirL1.Y(),dirL1.X()); | |
91 | ||
92 | //========================================================================= | |
0d969553 | 93 | // Processing of boundary cases. + |
7fd59977 | 94 | //========================================================================= |
95 | ||
96 | if (dirL1.IsEqual(OnLine.Direction(),Precision::Confusion()) && | |
97 | OnLine.Distance(originL1)<Precision::Confusion()) { | |
0d969553 | 98 | // POP : l2s 2 straight line are identic : no Sol |
7fd59977 | 99 | NbrSol = 0; |
100 | return ; | |
101 | } | |
102 | ||
103 | ||
104 | Standard_Real dp2l = OnLine.Distance(Point2); | |
105 | gp_Dir2d donline(OnLine.Direction()); | |
106 | gp_Pnt2d pinterm(Point2.XY()+dp2l*gp_XY(-donline.Y(),donline.X())); | |
107 | if (OnLine.Distance(pinterm) > Tol) { | |
108 | pinterm = gp_Pnt2d(Point2.XY()-dp2l*gp_XY(-donline.Y(),donline.X())); | |
109 | } | |
110 | Standard_Real dist = L1.Distance(pinterm); | |
111 | if (Abs(dist-dp2l) <= Tol) { | |
112 | gp_Dir2d dirbid(originL1.XY()-pinterm.XY()); | |
113 | if (Qualified1.IsEnclosed() && dirbid.Dot(normal)<0.) { | |
114 | WellDone = Standard_True; | |
115 | } | |
116 | else if (Qualified1.IsOutside() && dirbid.Dot(normal) > 0.) { | |
117 | WellDone = Standard_True; | |
118 | } | |
119 | else if (Qualified1.IsUnqualified()) { WellDone = Standard_True; } | |
120 | if (WellDone) { | |
121 | NbrSol++; | |
122 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),dp2l); | |
123 | // ====================================================== | |
124 | qualifier2(NbrSol) = GccEnt_noqualifier; | |
125 | gp_Dir2d dc2(originL1.XY()-pinterm.XY()); | |
126 | if (!Qualified1.IsUnqualified()) { | |
127 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
128 | } | |
129 | else if (dc2.Dot(normal) > 0.0) { | |
130 | qualifier1(NbrSol) = GccEnt_outside; | |
131 | } | |
132 | else { qualifier1(NbrSol) = GccEnt_enclosed; } | |
133 | Standard_Real sign = dc2.Dot(gp_Dir2d(-dirL1.Y(), | |
134 | dirL1.X())); | |
135 | dc2 = gp_Dir2d(sign*gp_XY(-dirL1.Y(),dirL1.X())); | |
136 | pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dp2l*dc2.XY()); | |
137 | pnttg2sol(NbrSol) = Point2; | |
138 | pntcen(NbrSol) = pinterm; | |
139 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol)); | |
140 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); | |
141 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol)); | |
142 | pararg2(NbrSol) = 0.; | |
143 | parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol)); | |
144 | return; | |
145 | } | |
146 | } | |
147 | ||
148 | //========================================================================= | |
0d969553 | 149 | // General case. + |
7fd59977 | 150 | //========================================================================= |
151 | ||
152 | GccAna_LinPnt2dBisec Bis(L1,Point2); | |
153 | if (Bis.IsDone()) { | |
154 | Handle(GccInt_Bisec) Sol = Bis.ThisSolution(); | |
155 | GccInt_IType type = Sol->ArcType(); | |
156 | IntAna2d_AnaIntersection Intp; | |
157 | if (type == GccInt_Lin) { | |
158 | Intp.Perform(OnLine,Sol->Line()); | |
159 | } | |
160 | if (type == GccInt_Par) { | |
161 | Intp.Perform(OnLine,IntAna2d_Conic(Sol->Parabola())); | |
162 | } | |
163 | if (Intp.IsDone()) { | |
164 | if (!Intp.IsEmpty()) { | |
165 | for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) { | |
166 | gp_Pnt2d Center(Intp.Point(j).Value()); | |
167 | Standard_Real Radius = L1.Distance(Center); | |
168 | // Standard_Integer nbsol = 1; | |
169 | Standard_Boolean ok = Standard_False; | |
170 | if (Qualified1.IsEnclosed()) { | |
171 | if ((((originL1.X()-Center.X())*(-dirL1.Y()))+ | |
172 | ((originL1.Y()-Center.Y())*(dirL1.X())))<=0){ | |
173 | ok = Standard_True; | |
174 | } | |
175 | } | |
176 | else if (Qualified1.IsOutside()) { | |
177 | if ((((originL1.X()-Center.X())*(-dirL1.Y()))+ | |
178 | ((originL1.Y()-Center.Y())*(dirL1.X())))>=0){ | |
179 | ok = Standard_True; | |
180 | } | |
181 | } | |
182 | else if (Qualified1.IsUnqualified()) { | |
183 | ok = Standard_True; | |
184 | } | |
185 | if (ok) { | |
186 | NbrSol++; | |
187 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius); | |
188 | // ======================================================= | |
189 | qualifier2(NbrSol) = GccEnt_noqualifier; | |
190 | gp_Dir2d dc2(originL1.XY()-Center.XY()); | |
191 | if (!Qualified1.IsUnqualified()) { | |
192 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
193 | } | |
194 | else if (dc2.Dot(normal) > 0.0) { | |
195 | qualifier1(NbrSol) = GccEnt_outside; | |
196 | } | |
197 | else { qualifier1(NbrSol) = GccEnt_enclosed; } | |
198 | TheSame1(NbrSol) = 0; | |
199 | TheSame2(NbrSol) = 0; | |
200 | gp_Dir2d dc1(originL1.XY()-Center.XY()); | |
201 | Standard_Real sign = dc1.Dot(gp_Dir2d(normal)); | |
202 | dc1=gp_Dir2d(sign*(normal.XY())); | |
203 | pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc1.XY()); | |
204 | pnttg2sol(NbrSol) = Point2; | |
205 | pntcen(NbrSol) = Center; | |
206 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
207 | pnttg1sol(NbrSol)); | |
208 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); | |
209 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
210 | pnttg2sol(NbrSol)); | |
211 | pararg2(NbrSol) = 0.; | |
212 | parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol)); | |
213 | } | |
214 | } | |
215 | } | |
216 | WellDone = Standard_True; | |
217 | } | |
218 | } | |
219 | } | |
220 |