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 <math_DirectPolynomialRoots.hxx> |
26 | #include <Standard_NegativeValue.hxx> | |
27 | #include <Standard_OutOfRange.hxx> | |
42cf5bc1 | 28 | #include <StdFail_NotDone.hxx> |
7fd59977 | 29 | |
30 | //========================================================================= | |
0d969553 | 31 | // typedef of handled objects : + |
7fd59977 | 32 | //========================================================================= |
7fd59977 | 33 | typedef math_DirectPolynomialRoots Roots; |
34 | ||
35 | //========================================================================= | |
0d969553 Y |
36 | // Circle tangent to a point Point1. + |
37 | // center on straight line OnLine. + | |
38 | // radius Radius. + | |
7fd59977 | 39 | // + |
0d969553 Y |
40 | // Initialize the table of solutions cirsol and all fields. + |
41 | // Eliminate cases not being the solution. + | |
42 | // Solve the equation of second degree showing that the found center point + | |
43 | // (xc,yc) is at distance Radius from point Point1 and on the straight line OnLine. + | |
44 | // The solutions are represented by circles : + | |
45 | // - of center Pntcen(xc,yc) + | |
46 | // - of radius Radius. + | |
7fd59977 | 47 | //========================================================================= |
48 | ||
49 | GccAna_Circ2dTanOnRad:: | |
50 | GccAna_Circ2dTanOnRad (const gp_Pnt2d& Point1 , | |
51 | const gp_Lin2d& OnLine , | |
52 | const Standard_Real Radius , | |
53 | const Standard_Real Tolerance ): | |
54 | cirsol(1,2) , | |
55 | qualifier1(1,2) , | |
56 | TheSame1(1,2) , | |
57 | pnttg1sol(1,2), | |
58 | pntcen3(1,2) , | |
59 | par1sol(1,2) , | |
60 | pararg1(1,2) , | |
61 | parcen3(1,2) | |
62 | { | |
63 | ||
64 | gp_Dir2d dirx(1.0,0.0); | |
65 | Standard_Real Tol = Abs(Tolerance); | |
66 | WellDone = Standard_False; | |
67 | NbrSol = 0; | |
68 | Standard_Real dp1lin = OnLine.Distance(Point1); | |
69 | ||
9775fa61 | 70 | if (Radius < 0.0) { throw Standard_NegativeValue(); } |
7fd59977 | 71 | else { |
72 | if (dp1lin > Radius+Tol) { WellDone = Standard_True; } | |
73 | Standard_Real xc; | |
74 | Standard_Real yc; | |
75 | Standard_Real x1 = Point1.X(); | |
76 | Standard_Real y1 = Point1.Y(); | |
77 | Standard_Real xbid = 0; | |
78 | Standard_Real xdir = (OnLine.Direction()).X(); | |
79 | Standard_Real ydir = (OnLine.Direction()).Y(); | |
80 | Standard_Real lxloc = (OnLine.Location()).X(); | |
81 | Standard_Real lyloc = (OnLine.Location()).Y(); | |
82 | if (Abs(dp1lin-Radius) < Tol) { | |
83 | WellDone = Standard_True; | |
84 | NbrSol = 1; | |
85 | if (-ydir*(x1-lxloc)+xdir*(y1-lyloc)<0.0) { | |
86 | gp_Ax2d axe(gp_Pnt2d(x1-ydir*dp1lin,y1+xdir*dp1lin),dirx); | |
87 | cirsol(NbrSol) = gp_Circ2d(axe,Radius); | |
88 | // ====================================== | |
89 | qualifier1(NbrSol) = GccEnt_noqualifier; | |
90 | } | |
91 | else { | |
92 | gp_Ax2d axe(gp_Pnt2d(x1+ydir*dp1lin,y1-xdir*dp1lin),dirx); | |
93 | cirsol(NbrSol) = gp_Circ2d(axe,Radius); | |
94 | // ====================================== | |
95 | qualifier1(NbrSol) = GccEnt_noqualifier; | |
96 | } | |
97 | TheSame1(NbrSol) = 0; | |
98 | pnttg1sol(NbrSol) = Point1; | |
99 | pntcen3(NbrSol) = cirsol(NbrSol).Location(); | |
100 | pararg1(NbrSol) = 0.0; | |
101 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol)); | |
102 | parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen3(NbrSol)); | |
103 | } | |
104 | else if (dp1lin < Tol) { | |
105 | pntcen3(1) = gp_Pnt2d(Point1.X()+Radius*xdir,Point1.Y()+Radius*ydir); | |
106 | pntcen3(2) = gp_Pnt2d(Point1.X()-Radius*xdir,Point1.Y()-Radius*ydir); | |
107 | pntcen3(1) = ElCLib::Value(ElCLib::Parameter(OnLine,pntcen3(1)),OnLine); | |
108 | pntcen3(2) = ElCLib::Value(ElCLib::Parameter(OnLine,pntcen3(2)),OnLine); | |
109 | gp_Ax2d axe(pntcen3(1),OnLine.Direction()); | |
110 | cirsol(1) = gp_Circ2d(axe,Radius); | |
111 | axe = gp_Ax2d(pntcen3(2),OnLine.Direction()); | |
112 | cirsol(2) = gp_Circ2d(axe,Radius); | |
113 | TheSame1(1) = 0; | |
114 | pnttg1sol(1) = Point1; | |
115 | pararg1(1) = 0.0; | |
116 | par1sol(1)=ElCLib::Parameter(cirsol(1),pnttg1sol(1)); | |
117 | parcen3(1)=ElCLib::Parameter(OnLine,pntcen3(1)); | |
118 | TheSame1(2) = 0; | |
119 | pnttg1sol(2) = Point1; | |
120 | pararg1(2) = 0.0; | |
121 | par1sol(2)=ElCLib::Parameter(cirsol(2),pnttg1sol(2)); | |
122 | parcen3(2)=ElCLib::Parameter(OnLine,pntcen3(2)); | |
123 | NbrSol = 2; | |
124 | } | |
125 | else { | |
126 | Standard_Real A,B,C; | |
127 | OnLine.Coefficients(A,B,C); | |
128 | Standard_Real D = A; | |
129 | if (A == 0.0) { | |
130 | A = B; | |
131 | B = D; | |
132 | xbid = x1; | |
133 | x1 = y1; | |
134 | y1 = xbid; | |
135 | } | |
136 | if (A != 0.0) { | |
137 | Roots Sol((B*B+A*A)/(A*A), | |
138 | 2.0*(B*C/(A*A)+(B/A)*x1-y1), | |
139 | x1*x1+y1*y1+C*C/(A*A)-Radius*Radius+2.0*C*x1/A); | |
140 | if (Sol.IsDone()) { | |
141 | for (Standard_Integer i = 1 ; i <= Sol.NbSolutions() ; i++) { | |
142 | if (D != 0.0) { | |
143 | yc = Sol.Value(i); | |
144 | xc = -(B/A)*yc-C/A; | |
145 | } | |
146 | else { | |
147 | xc = Sol.Value(i); | |
148 | yc = -(B/A)*xc-C/A; | |
149 | } | |
150 | NbrSol++; | |
151 | gp_Pnt2d Center(xc,yc); | |
152 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius); | |
153 | // ======================================================= | |
154 | qualifier1(NbrSol) = GccEnt_noqualifier; | |
155 | TheSame1(NbrSol) = 0; | |
156 | pnttg1sol(NbrSol) = Point1; | |
157 | pntcen3(NbrSol) = cirsol(NbrSol).Location(); | |
158 | pararg1(NbrSol) = 0.0; | |
159 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol), | |
160 | pnttg1sol(NbrSol)); | |
161 | parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen3(NbrSol)); | |
162 | } | |
163 | WellDone = Standard_True; | |
164 | } | |
165 | } | |
166 | } | |
167 | } | |
168 | } |