1 //File GccAna_Lin2dTanObl.cxx, REG 08/07/91
3 //=========================================================================
4 // CREATION of a STRAIGHT LINE TANGENT to a CIRCLE or PASSING by a POINT +
5 // and MAKING ANGLE A with a STRAIGHT LINE. +
6 //=========================================================================
8 #include <GccAna_Lin2dTanObl.ixx>
11 #include <StdFail_NotDone.hxx>
13 #include <gp_Dir2d.hxx>
14 #include <gp_Vec2d.hxx>
15 #include <gp_Circ2d.hxx>
16 #include <IntAna2d_AnaIntersection.hxx>
17 #include <IntAna2d_IntPoint.hxx>
18 #include <Standard_OutOfRange.hxx>
19 #include <GccEnt_BadQualifier.hxx>
21 //=========================================================================
22 // Creation of a straight line passing by a point : ThePoint +
23 // making an angle : TheAngle +
24 // with straight line : TheLine. +
25 // Subject the straight line (ThePoint,TheLine.Location()) to a rotation +
26 // by angle TheAngle ==> D1. +
27 // create straight line passing through ThePoint of direction D1. +
28 //=========================================================================
31 GccAna_Lin2dTanObl (const gp_Pnt2d& ThePoint ,
32 const gp_Lin2d& TheLine ,
33 const Standard_Real TheAngle ):
44 Standard_Real Cosa = TheLine.Direction().X();
45 Standard_Real Sina = TheLine.Direction().Y();
46 linsol(1) = gp_Lin2d(ThePoint,
47 // ==============================
48 gp_Dir2d(Cosa*Cos(TheAngle)-Sina*Sin(TheAngle),
49 // ===============================================
50 Sina*Cos(TheAngle)+Sin(TheAngle)*Cosa));
51 // =======================================
52 qualifier1(1) = GccEnt_noqualifier;
53 pnttg1sol(1) = ThePoint;
54 IntAna2d_AnaIntersection Intp(linsol(1),TheLine);
56 if (!Intp.IsEmpty()) {
57 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
58 pntint2sol(1) = Intp.Point(i).Value();
61 par1sol(1)=ElCLib::Parameter(linsol(1),pnttg1sol(1));
62 par2sol(1)=ElCLib::Parameter(linsol(1),pntint2sol(1));
64 pararg2(1)=ElCLib::Parameter(TheLine,pntint2sol(1));
66 WellDone = Standard_True;
69 WellDone = Standard_False;
74 //=========================================================================
75 // Creation of a straight line tangent to a circle : Qualified1 (C1) +
76 // making angle : TheAngle +
77 // with a straight line : TheLine. +
78 // Subject the straight line (C1.Location,TheLine.Location()) to a +
79 // rotation by angle TheAngle or -TheAngle ==> D1. +
80 // create the straight line passing by C1 of direction D1. +
81 //=========================================================================
84 GccAna_Lin2dTanObl (const GccEnt_QualifiedCirc& Qualified1 ,
85 const gp_Lin2d& TheLine ,
86 const Standard_Real TheAngle ):
97 WellDone = Standard_False;
99 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
100 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
101 GccEnt_BadQualifier::Raise();
104 Standard_Real Cosa = TheLine.Direction().X();
105 Standard_Real Sina = TheLine.Direction().Y();
106 if (Qualified1.IsEnclosed()) {
107 // ============================
108 GccEnt_BadQualifier::Raise();
111 gp_Circ2d C1 = Qualified1.Qualified();
112 Standard_Real R1 = C1.Radius();
113 if (Qualified1.IsEnclosing()) {
114 // =============================
115 gp_XY xy(Cos(TheAngle)*Cosa-Sin(TheAngle)*Sina,
116 Cos(TheAngle)*Sina+Sin(TheAngle)*Cosa);
117 pnttg1sol(1) = gp_Pnt2d(C1.Location().XY()+R1*gp_XY(xy.Y(),-xy.X()));
118 linsol(1) = gp_Lin2d(pnttg1sol(1),gp_Dir2d(xy));
119 // ===============================================
120 qualifier1(1) = Qualified1.Qualifier();
121 IntAna2d_AnaIntersection Intp(linsol(1),TheLine);
123 WellDone = Standard_True;
125 if (!Intp.IsEmpty()) {
126 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
127 pntint2sol(1) = Intp.Point(i).Value();
132 else if (Qualified1.IsOutside()) {
133 // ================================
134 gp_XY xy(Cos(TheAngle)*Cosa-Sin(TheAngle)*Sina,
135 Cos(TheAngle)*Sina+Sin(TheAngle)*Cosa);
136 pnttg1sol(1) = gp_Pnt2d(C1.Location().XY()+R1*gp_XY(-xy.Y(),xy.X()));
137 linsol(1) = gp_Lin2d(pnttg1sol(1),gp_Dir2d(xy));
138 // ===============================================
139 qualifier1(1) = Qualified1.Qualifier();
140 IntAna2d_AnaIntersection Intp(linsol(1),TheLine);
141 WellDone = Standard_True;
144 if (!Intp.IsEmpty()) {
145 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
146 pntint2sol(1) = Intp.Point(i).Value();
151 else if (Qualified1.IsUnqualified()) {
152 // ====================================
153 gp_XY xy(Cos(TheAngle)*Cosa-Sin(TheAngle)*Sina,
154 Cos(TheAngle)*Sina+Sin(TheAngle)*Cosa);
155 pnttg1sol(1) = gp_Pnt2d(C1.Location().XY()+R1*gp_XY(xy.Y(),-xy.X()));
156 linsol(1) = gp_Lin2d(pnttg1sol(1),gp_Dir2d(xy));
157 // ===============================================
158 qualifier1(1) = GccEnt_enclosing;
159 IntAna2d_AnaIntersection Intp(linsol(1),TheLine);
160 WellDone = Standard_True;
163 if (!Intp.IsEmpty()) {
164 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
165 pntint2sol(1) = Intp.Point(i).Value();
169 pnttg1sol(2) = gp_Pnt2d(C1.Location().XY()+R1*gp_XY(-xy.Y(),xy.X()));
170 linsol(2) = gp_Lin2d(pnttg1sol(2),gp_Dir2d(xy));
171 // ===============================================
172 qualifier1(2) = GccEnt_outside;
173 Intp = IntAna2d_AnaIntersection(linsol(1),TheLine);
175 WellDone = Standard_True;
177 if (!Intp.IsEmpty()) {
178 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
179 pntint2sol(2) = Intp.Point(i).Value();
184 for (Standard_Integer index = 1; index <= NbrSol; index++) {
185 par1sol(index)=ElCLib::Parameter(linsol(index),pnttg1sol(index));
186 pararg1(index)=ElCLib::Parameter(C1,pnttg1sol(index));
187 par2sol(index)=ElCLib::Parameter(linsol(index),pntint2sol(index));
188 pararg2(index)=ElCLib::Parameter(TheLine,pntint2sol(index));
193 Standard_Boolean GccAna_Lin2dTanObl::
194 IsDone () const { return WellDone; }
196 Standard_Integer GccAna_Lin2dTanObl::
199 if (!WellDone) StdFail_NotDone::Raise();
203 gp_Lin2d GccAna_Lin2dTanObl::
204 ThisSolution (const Standard_Integer Index) const
207 StdFail_NotDone::Raise();
208 if (Index <= 0 || Index > NbrSol)
209 Standard_OutOfRange::Raise();
211 return linsol(Index);
214 void GccAna_Lin2dTanObl::
215 WhichQualifier(const Standard_Integer Index ,
216 GccEnt_Position& Qualif1 ) const
218 if (!WellDone) { StdFail_NotDone::Raise(); }
219 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
221 Qualif1 = qualifier1(Index);
225 void GccAna_Lin2dTanObl::
226 Tangency1 (const Standard_Integer Index,
227 Standard_Real& ParSol,
228 Standard_Real& ParArg,
229 gp_Pnt2d& PntSol) const{
230 if (!WellDone) { StdFail_NotDone::Raise(); }
231 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
233 ParSol = par1sol(Index);
234 ParArg = pararg1(Index);
235 PntSol = gp_Pnt2d(pnttg1sol(Index));
239 void GccAna_Lin2dTanObl::
240 Intersection2 (const Standard_Integer Index,
241 Standard_Real& ParSol,
242 Standard_Real& ParArg,
243 gp_Pnt2d& PntSol) const{
244 if (!WellDone) { StdFail_NotDone::Raise(); }
245 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
247 ParSol = par2sol(Index);
248 ParArg = pararg2(Index);
249 PntSol = gp_Pnt2d(pntint2sol(Index));