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 | |
7fd59977 |
15 | |
16 | #include <ElCLib.hxx> |
42cf5bc1 |
17 | #include <GccAna_Circ2d3Tan.hxx> |
7fd59977 |
18 | #include <GccAna_Lin2dBisec.hxx> |
42cf5bc1 |
19 | #include <GccAna_LinPnt2dBisec.hxx> |
7fd59977 |
20 | #include <GccAna_Pnt2dBisec.hxx> |
42cf5bc1 |
21 | #include <GccEnt_BadQualifier.hxx> |
22 | #include <GccEnt_QualifiedCirc.hxx> |
23 | #include <GccEnt_QualifiedLin.hxx> |
7fd59977 |
24 | #include <GccInt_Bisec.hxx> |
25 | #include <GccInt_IType.hxx> |
42cf5bc1 |
26 | #include <gp_Circ2d.hxx> |
27 | #include <gp_Dir2d.hxx> |
28 | #include <gp_Lin2d.hxx> |
29 | #include <gp_Pnt2d.hxx> |
30 | #include <IntAna2d_AnaIntersection.hxx> |
7fd59977 |
31 | #include <IntAna2d_Conic.hxx> |
42cf5bc1 |
32 | #include <IntAna2d_IntPoint.hxx> |
7fd59977 |
33 | #include <Precision.hxx> |
42cf5bc1 |
34 | #include <Standard_OutOfRange.hxx> |
35 | #include <StdFail_NotDone.hxx> |
36 | |
7fd59977 |
37 | //========================================================================= |
0d969553 |
38 | // Creation of a circle tangent to a straight line and two points. + |
7fd59977 |
39 | //========================================================================= |
7fd59977 |
40 | GccAna_Circ2d3Tan:: |
41 | GccAna_Circ2d3Tan (const GccEnt_QualifiedLin& Qualified1, |
42 | const gp_Pnt2d& Point2 , |
43 | const gp_Pnt2d& Point3 , |
44 | const Standard_Real Tolerance ): |
45 | |
46 | cirsol(1,2) , |
47 | qualifier1(1,2) , |
48 | qualifier2(1,2) , |
49 | qualifier3(1,2) , |
50 | TheSame1(1,2) , |
51 | TheSame2(1,2) , |
52 | TheSame3(1,2) , |
53 | pnttg1sol(1,2) , |
54 | pnttg2sol(1,2) , |
55 | pnttg3sol(1,2) , |
56 | par1sol(1,2) , |
57 | par2sol(1,2) , |
58 | par3sol(1,2) , |
59 | pararg1(1,2) , |
60 | pararg2(1,2) , |
61 | pararg3(1,2) |
62 | { |
63 | |
64 | WellDone = Standard_False; |
65 | Standard_Real Tol = Abs(Tolerance); |
66 | gp_Dir2d dirx(1.0,0.0); |
67 | NbrSol = 0; |
68 | if (!(Qualified1.IsEnclosed() || |
69 | Qualified1.IsOutside() || Qualified1.IsUnqualified())) { |
9775fa61 |
70 | throw GccEnt_BadQualifier(); |
7fd59977 |
71 | return; |
72 | } |
73 | |
74 | //========================================================================= |
0d969553 |
75 | // Processing. + |
7fd59977 |
76 | //========================================================================= |
77 | |
78 | gp_Lin2d L1 = Qualified1.Qualified(); |
79 | gp_Pnt2d origin1(L1.Location()); |
80 | gp_Dir2d dir1(L1.Direction()); |
81 | gp_Dir2d normL1(-dir1.Y(),dir1.X()); |
82 | |
83 | if (Point2.IsEqual(Point3,Precision::Confusion())) { |
84 | WellDone = Standard_False; |
85 | return ; |
86 | } |
87 | |
88 | GccAna_Pnt2dBisec Bis1(Point2,Point3); |
89 | GccAna_LinPnt2dBisec Bis2(L1,Point2); |
90 | if (Bis1.IsDone() && Bis2.IsDone()) { |
8dbf0462 |
91 | const gp_Lin2d linint1(Bis1.ThisSolution()); |
7fd59977 |
92 | Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution(); |
93 | GccInt_IType typ2 = Sol2->ArcType(); |
7fd59977 |
94 | IntAna2d_AnaIntersection Intp; |
95 | if (typ2 == GccInt_Lin) { |
96 | gp_Lin2d linint2(Sol2->Line()); |
97 | Intp.Perform (linint1,linint2); |
98 | } |
99 | else if (typ2 == GccInt_Par) { |
100 | Intp.Perform (linint1,IntAna2d_Conic(Sol2->Parabola())); |
101 | } |
102 | if (Intp.IsDone()) { |
103 | if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&& |
104 | (!Intp.IdenticalElements())) { |
105 | for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) { |
106 | gp_Pnt2d Center(Intp.Point(j).Value()); |
107 | Standard_Real dist1 = L1.Distance(Center); |
108 | Standard_Real dist2 = Center.Distance(Point2); |
6e6cd5d9 |
109 | |
7fd59977 |
110 | Standard_Real Radius=0; |
7fd59977 |
111 | Standard_Integer nbsol3 = 0; |
112 | Standard_Boolean ok = Standard_False; |
f2fd3809 |
113 | Standard_Real difference = (((origin1.X()-Center.X())*(-dir1.Y())) + ((origin1.Y()-Center.Y())*(dir1.X()))); |
114 | if ((Qualified1.IsEnclosed() && difference <= 0) || |
115 | (Qualified1.IsOutside() && difference >= 0) || |
116 | (Qualified1.IsUnqualified())) |
117 | { |
118 | ok = Standard_True; |
f2fd3809 |
119 | Radius = dist1; |
120 | } |
7fd59977 |
121 | if (ok) { |
f2fd3809 |
122 | if (Abs(dist2-Radius)<=Tol) { |
7fd59977 |
123 | nbsol3 = 1; |
124 | } |
125 | else { ok = Standard_False; } |
126 | } |
127 | if (ok) { |
128 | for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) { |
129 | NbrSol++; |
130 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius); |
131 | // ======================================================= |
132 | gp_Dir2d dc1(origin1.XY()-Center.XY()); |
133 | if (!Qualified1.IsUnqualified()) { |
134 | qualifier1(NbrSol) = Qualified1.Qualifier(); |
135 | } |
136 | else if (dc1.Dot(normL1) > 0.0) { |
137 | qualifier1(NbrSol) = GccEnt_outside; |
138 | } |
139 | else { qualifier1(NbrSol) = GccEnt_enclosed; } |
140 | qualifier2(NbrSol) = GccEnt_noqualifier; |
141 | qualifier3(NbrSol) = GccEnt_noqualifier; |
142 | TheSame1(NbrSol) = 0; |
143 | gp_Dir2d dc(origin1.XY()-Center.XY()); |
144 | Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X())); |
145 | dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X())); |
146 | pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY()); |
147 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
148 | pnttg1sol(NbrSol)); |
149 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); |
150 | TheSame2(NbrSol) = 0; |
151 | pnttg2sol(NbrSol) = Point2; |
152 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
153 | pnttg2sol(NbrSol)); |
154 | pararg2(NbrSol) = 0.; |
155 | TheSame3(NbrSol) = 0; |
156 | pnttg3sol(NbrSol) = Point3; |
157 | par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), |
158 | pnttg3sol(NbrSol)); |
159 | pararg3(NbrSol) = 0.; |
160 | } |
161 | } |
162 | } |
163 | } |
164 | WellDone = Standard_True; |
165 | } |
166 | } |
167 | } |
168 | |