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 | |
7fd59977 | 15 | |
16 | #include <ElCLib.hxx> | |
42cf5bc1 | 17 | #include <GccAna_Circ2dTanOnRad.hxx> |
18 | #include <GccEnt_BadQualifier.hxx> | |
19 | #include <GccEnt_QualifiedCirc.hxx> | |
20 | #include <GccEnt_QualifiedLin.hxx> | |
21 | #include <gp_Circ2d.hxx> | |
22 | #include <gp_Dir2d.hxx> | |
23 | #include <gp_Lin2d.hxx> | |
24 | #include <gp_Pnt2d.hxx> | |
7fd59977 | 25 | #include <IntAna2d_AnaIntersection.hxx> |
26 | #include <IntAna2d_IntPoint.hxx> | |
7fd59977 | 27 | #include <Standard_NegativeValue.hxx> |
7fd59977 | 28 | #include <Standard_OutOfRange.hxx> |
42cf5bc1 | 29 | #include <StdFail_NotDone.hxx> |
30 | #include <TColStd_Array1OfInteger.hxx> | |
7fd59977 | 31 | |
32 | //========================================================================= | |
0d969553 Y |
33 | // Circle tangent to straight line Qualified1 (L1) + |
34 | // center on straight line OnLine + | |
35 | // of radius Radius. + | |
7fd59977 | 36 | // + |
0d969553 Y |
37 | // Initialize the table of solutions cirsol and all fields. + |
38 | // Elimine depending on the qualifier the cases not being solutions. + | |
39 | // Create L1para : parallel to L1 in the direction required by the + | |
40 | // qualifier at distance Radius. + | |
41 | // Point P of intersection between L1para and OnLine will give the center point + | |
42 | // of the solution. + | |
43 | // Create solutions cirsol with center P and radius Radius. + | |
44 | // Fill the fields. + | |
7fd59977 | 45 | //========================================================================= |
7fd59977 | 46 | GccAna_Circ2dTanOnRad:: |
47 | GccAna_Circ2dTanOnRad (const GccEnt_QualifiedLin& Qualified1, | |
48 | const gp_Lin2d& OnLine , | |
49 | const Standard_Real Radius , | |
50 | const Standard_Real Tolerance ): | |
51 | cirsol(1,2) , | |
52 | qualifier1(1,2) , | |
53 | TheSame1(1,2) , | |
54 | pnttg1sol(1,2) , | |
55 | pntcen3(1,2) , | |
56 | par1sol(1,2) , | |
57 | pararg1(1,2) , | |
58 | parcen3(1,2) | |
59 | { | |
60 | ||
61 | Standard_Real Tol =Abs(Tolerance); | |
62 | gp_Dir2d dirx(1.0,0.0); | |
63 | WellDone = Standard_False; | |
64 | NbrSol = 0; | |
65 | if (!(Qualified1.IsEnclosed() || | |
66 | Qualified1.IsOutside() || Qualified1.IsUnqualified())) { | |
9775fa61 | 67 | throw GccEnt_BadQualifier(); |
7fd59977 | 68 | return; |
69 | } | |
70 | Standard_Integer nbsol = 0; | |
71 | TColStd_Array1OfInteger eps(1,2); | |
72 | gp_Lin2d L1 = Qualified1.Qualified(); | |
73 | gp_Pnt2d origin1(L1.Location()); | |
74 | gp_Dir2d dir1(L1.Direction()); | |
75 | gp_Dir2d normL1(-dir1.Y(),dir1.X()); | |
76 | ||
9775fa61 | 77 | if (Radius < 0.0) { throw Standard_NegativeValue(); } |
7fd59977 | 78 | else if ((OnLine.Direction()).IsParallel(dir1,Tol)) { |
79 | WellDone = Standard_True; | |
80 | } | |
81 | else { | |
82 | if (Qualified1.IsEnclosed()) { | |
83 | // ============================ | |
84 | eps(1) = -1; | |
85 | nbsol = 1; | |
86 | } | |
87 | else if (Qualified1.IsOutside()) { | |
88 | // ================================ | |
89 | eps(1) = 1; | |
90 | nbsol = 1; | |
91 | } | |
92 | else { | |
93 | // ==== | |
94 | eps(1) = 1; | |
95 | eps(2) = -1; | |
96 | nbsol = 2; | |
97 | } | |
98 | Standard_Real dx1 = dir1.X(); | |
99 | Standard_Real dy1 = dir1.Y(); | |
100 | Standard_Real lx1 = origin1.X(); | |
101 | Standard_Real ly1 = origin1.Y(); | |
102 | for (Standard_Integer j = 1 ; j <= nbsol ; j++) { | |
103 | gp_Lin2d L1para(gp_Pnt2d(lx1+eps(j)*Radius*dy1,ly1-eps(j)*Radius*dx1), | |
104 | dir1); | |
105 | IntAna2d_AnaIntersection Intp(OnLine,L1para); | |
106 | if (Intp.IsDone()) { | |
107 | if (!Intp.IsEmpty()) { | |
108 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
109 | NbrSol++; | |
110 | gp_Pnt2d Center(Intp.Point(i).Value()); | |
111 | cirsol(NbrSol)=gp_Circ2d(gp_Ax2d(Center,dirx),Radius); | |
112 | // ===================================================== | |
113 | gp_Dir2d dc1(origin1.XY()-Center.XY()); | |
7fd59977 | 114 | if (!Qualified1.IsUnqualified()) { |
115 | qualifier1(NbrSol) = Qualified1.Qualifier(); | |
116 | } | |
117 | else if (dc1.Dot(normL1) > 0.0) { | |
118 | qualifier1(NbrSol) = GccEnt_outside; | |
119 | } | |
120 | else { qualifier1(NbrSol) = GccEnt_enclosed; } | |
121 | TheSame1(NbrSol) = 0; | |
122 | if (gp_Vec2d(Center,origin1).Dot(gp_Dir2d(-dy1,dx1))>0.0) { | |
123 | pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius*gp_XY(-dy1,dx1)); | |
124 | pntcen3(NbrSol) = cirsol(1).Location(); | |
125 | } | |
126 | else { | |
127 | pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()-Radius*gp_XY(-dy1,dx1)); | |
128 | pntcen3(NbrSol) = cirsol(1).Location(); | |
129 | } | |
130 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
131 | pnttg1sol(NbrSol)); | |
132 | pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol)); | |
133 | parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen3(NbrSol)); | |
134 | } | |
135 | } | |
136 | WellDone = Standard_True; | |
137 | } | |
138 | } | |
139 | } | |
140 | } |