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 | |
578ce4be |
15 | #include <Geom2dGcc_Circ2dTanCenGeo.ixx> |
16 | |
7fd59977 |
17 | #include <StdFail_NotDone.hxx> |
18 | #include <Standard_OutOfRange.hxx> |
19 | #include <Standard_Failure.hxx> |
20 | #include <gp.hxx> |
21 | #include <gp_Ax2d.hxx> |
22 | #include <gp_Vec2d.hxx> |
23 | #include <TColStd_Array1OfInteger.hxx> |
24 | #include <TColStd_Array1OfReal.hxx> |
25 | #include <Extrema_POnCurv2d.hxx> |
26 | |
578ce4be |
27 | #include <Geom2dGcc_CurveTool.hxx> |
28 | #include <Extrema_ExtPC2d.hxx> |
29 | |
7fd59977 |
30 | //========================================================================= |
31 | // Creation d un cercle tangent a une courbe centre en un point. + |
32 | //========================================================================= |
33 | |
578ce4be |
34 | Geom2dGcc_Circ2dTanCenGeo:: |
35 | Geom2dGcc_Circ2dTanCenGeo (const Geom2dGcc_QCurve& Qualified1, |
36 | const gp_Pnt2d& Pcenter , |
37 | const Standard_Real Tolerance ): |
7fd59977 |
38 | |
39 | //======================================================================== |
40 | // Initialisation des champs. + |
41 | //======================================================================== |
42 | |
578ce4be |
43 | cirsol(1,2) , |
44 | qualifier1(1,2), |
45 | pnttg1sol(1,2) , |
46 | par1sol(1,2) , |
47 | pararg1(1,2) |
7fd59977 |
48 | { |
7fd59977 |
49 | Standard_Real Tol = Abs(Tolerance); |
50 | TColgp_Array1OfPnt2d pTan(1,2); |
51 | TColStd_Array1OfInteger Index(1,2); |
52 | TColStd_Array1OfReal theDist2(1,2); |
53 | TColStd_Array1OfReal theParam(1,2); |
54 | theDist2(1) = RealLast(); |
55 | theDist2(2) = 0.; |
56 | Standard_Integer i = 1; |
57 | Standard_Integer nbsol = 0; |
58 | gp_Dir2d dirx(1.0,0.0); |
59 | Standard_Real thePar; |
578ce4be |
60 | Geom2dAdaptor_Curve curve = Qualified1.Qualified(); |
61 | Extrema_ExtPC2d distmin(Pcenter,curve,Geom2dGcc_CurveTool::NbSamples(curve), |
62 | Geom2dGcc_CurveTool::EpsX(curve,Tol),Tol); |
7fd59977 |
63 | if (!distmin.IsDone() ) { Standard_Failure::Raise(); } |
64 | Standard_Integer nbext = distmin.NbExt(); |
65 | if(nbext==0) { Standard_Failure::Raise(); } |
66 | while (i<=nbext) { |
67 | thePar = distmin.Point(i).Parameter(); |
68 | if (distmin.SquareDistance(i)<theDist2(1) && |
578ce4be |
69 | thePar>=Geom2dGcc_CurveTool::FirstParameter(curve) && |
70 | thePar <= Geom2dGcc_CurveTool::LastParameter(curve)) { |
71 | theDist2(1) = distmin.SquareDistance(i); |
72 | theParam(1) = thePar; |
73 | pTan(1) = distmin.Point(i).Value(); |
7fd59977 |
74 | } |
75 | if (distmin.SquareDistance(i)>theDist2(2) && |
578ce4be |
76 | thePar>=Geom2dGcc_CurveTool::FirstParameter(curve) && |
77 | thePar <= Geom2dGcc_CurveTool::LastParameter(curve)) { |
78 | theDist2(2) = distmin.SquareDistance(i); |
79 | theParam(2) = thePar; |
80 | pTan(2) = distmin.Point(i).Value(); |
7fd59977 |
81 | } |
82 | i++; |
83 | } |
84 | if (Index(1) == Index(2)) { nbsol = 1; } |
85 | else { nbsol = 2; } |
86 | for (i = 1 ; i <= nbsol; i++) { |
87 | gp_Pnt2d point1; |
88 | gp_Vec2d Tan1; |
578ce4be |
89 | Geom2dGcc_CurveTool::D1(curve,theParam(i),point1,Tan1); |
7fd59977 |
90 | Standard_Real normetan1 = Tan1.Magnitude(); |
91 | gp_Vec2d Vec1(point1,Pcenter); |
92 | Standard_Real normevec1 = Vec1.Magnitude(); |
93 | Standard_Real dot1; |
94 | if (normevec1 >= gp::Resolution() && normetan1 >= gp::Resolution()) { |
95 | dot1 = Vec1.Dot(Tan1)/(normevec1*normetan1); |
96 | } |
97 | else { dot1 = 0.; } |
98 | Tol = 1.e-12; |
99 | if (dot1 <= Tol) { |
100 | Standard_Real Angle1 = Vec1.Angle(Tan1); |
101 | if (Qualified1.IsUnqualified()|| |
578ce4be |
102 | (Qualified1.IsEnclosing()&&Angle1<=0.)|| |
103 | (Qualified1.IsOutside() && Angle1 >= 0.) || |
104 | (Qualified1.IsEnclosed() && Angle1 <= 0.)) { |
105 | NbrSol++; |
106 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Pcenter,dirx),sqrt (theDist2(i))); |
107 | qualifier1(NbrSol) = Qualified1.Qualifier(); |
108 | pararg1(NbrSol) = theParam(i); |
109 | par1sol(NbrSol) = 0.; |
110 | pnttg1sol(NbrSol) = pTan(i); |
111 | WellDone = Standard_True; |
7fd59977 |
112 | } |
113 | } |
114 | } |
115 | } |
116 | |
117 | |
118 | |
119 | //========================================================================= |
120 | |
121 | |
578ce4be |
122 | Standard_Boolean Geom2dGcc_Circ2dTanCenGeo:: |
123 | IsDone () const { return WellDone; } |
7fd59977 |
124 | |
578ce4be |
125 | Standard_Integer Geom2dGcc_Circ2dTanCenGeo:: |
126 | NbSolutions () const { return NbrSol; } |
7fd59977 |
127 | |
578ce4be |
128 | gp_Circ2d Geom2dGcc_Circ2dTanCenGeo:: |
129 | ThisSolution (const Standard_Integer Index) const |
7fd59977 |
130 | { |
131 | if (Index > NbrSol || Index <= 0) Standard_OutOfRange::Raise(); |
132 | |
133 | return cirsol(Index); |
134 | } |
135 | |
578ce4be |
136 | void Geom2dGcc_Circ2dTanCenGeo:: |
137 | WhichQualifier(const Standard_Integer Index , |
138 | GccEnt_Position& Qualif1 ) const |
7fd59977 |
139 | { |
140 | if (!WellDone) { StdFail_NotDone::Raise(); } |
141 | else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); } |
142 | else { |
143 | Qualif1 = qualifier1(Index); |
144 | } |
145 | } |
146 | |
578ce4be |
147 | void Geom2dGcc_Circ2dTanCenGeo:: |
148 | Tangency1 (const Standard_Integer Index, |
149 | Standard_Real& ParSol, |
150 | Standard_Real& ParArg, |
151 | gp_Pnt2d& PntSol) const{ |
152 | if (!WellDone) { |
153 | StdFail_NotDone::Raise(); |
154 | } |
155 | else if (Index <= 0 ||Index > NbrSol) { |
156 | Standard_OutOfRange::Raise(); |
157 | } |
158 | else { |
159 | PntSol = gp_Pnt2d(pnttg1sol(Index)); |
160 | ParSol = par1sol(Index); |
161 | ParArg = pararg1(Index); |
162 | } |
163 | } |
7fd59977 |
164 | |