1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 //=========================================================================
16 // CREATION of a STRAIGHT LINE TANGENT to a CIRCLE or PASSING by a POINT +
17 // and ORTHOGONAL to a STRAIGHT LINE. +
18 //=========================================================================
20 #include <GccAna_Lin2dTanPer.ixx>
23 #include <StdFail_NotDone.hxx>
25 #include <gp_Dir2d.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <gp_Circ2d.hxx>
28 #include <Standard_OutOfRange.hxx>
29 #include <GccEnt_BadQualifier.hxx>
30 #include <IntAna2d_AnaIntersection.hxx>
31 #include <IntAna2d_IntPoint.hxx>
33 //=========================================================================
34 // Straight line passing by point : ThePoint and +
35 // orthogonal to straight line : TheLin. +
36 // Create the straight line of origin : ThePoint +
37 // and direction : TheLin.Direction() turned by 90 +
38 //=========================================================================
41 GccAna_Lin2dTanPer (const gp_Pnt2d& ThePnt ,
42 const gp_Lin2d& TheLin ):
53 linsol(1) = gp_Lin2d(ThePnt,gp_Dir2d(-(TheLin.Direction().Y()),
54 // ===============================================================
55 TheLin.Direction().X()));
56 // ========================
57 pnttg1sol(1) = ThePnt;
58 IntAna2d_AnaIntersection Intp(linsol(1),TheLin);
60 if (!Intp.IsEmpty()) {
61 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
62 pntint2sol(1) = Intp.Point(i).Value();
66 par1sol(1) = ElCLib::Parameter(linsol(1),pnttg1sol(1));
67 par2sol(1) = ElCLib::Parameter(linsol(1),pntint2sol(1));
69 pararg2(1) = ElCLib::Parameter(TheLin,pntint2sol(1));
71 WellDone = Standard_True;
74 //=========================================================================
75 // Straight line passing by point : ThePnt +
76 // and orthogonal to circle : TheCircle. +
77 // Create the straight line of origin : ThePoint +
78 // and direction : (TheCircle.Location(),ThePnt). +
79 //=========================================================================
82 GccAna_Lin2dTanPer (const gp_Pnt2d& ThePnt ,
83 const gp_Circ2d& TheCircle ):
94 linsol(1) = gp_Lin2d(ThePnt,
95 // ============================
96 gp_Dir2d(TheCircle.Location().XY()-ThePnt.XY()));
97 // ================================================
98 pnttg1sol(1) = ThePnt;
99 IntAna2d_AnaIntersection Intp(linsol(1),TheCircle);
101 if (!Intp.IsEmpty()) {
102 Standard_Real maxdist = RealLast();
103 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
104 if (Intp.Point(i).Value().Distance(ThePnt) < maxdist) {
105 pntint2sol(1) = Intp.Point(i).Value();
110 par1sol(1) = ElCLib::Parameter(linsol(1),pnttg1sol(1));
111 par2sol(1) = ElCLib::Parameter(linsol(1),pntint2sol(1));
113 pararg2(1) = ElCLib::Parameter(TheCircle,pntint2sol(1));
115 WellDone = Standard_True;
118 //=========================================================================
119 // Straight line tangent to circle : Qualified1 (C1) +
120 // and orthogonal to straight line : TheLin. +
121 // Create straight line of origin : P1 (on C1) +
122 // and direction : TheLin.Direction() turned by 90` +
123 //=========================================================================
126 GccAna_Lin2dTanPer (const GccEnt_QualifiedCirc& Qualified1,
127 const gp_Lin2d& TheLin ):
138 WellDone = Standard_False;
139 Standard_Integer nbsol = 0;
140 Standard_Integer signe = 0;
142 gp_Circ2d C1 = Qualified1.Qualified();
144 if (Qualified1.IsEnclosed()) {
145 // ============================
146 GccEnt_BadQualifier::Raise();
148 else if (Qualified1.IsEnclosing()) {
149 // ==================================
153 else if (Qualified1.IsOutside()) {
154 // ================================
162 gp_XY xy(C1.Radius()*TheLin.Direction().XY());
163 for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
166 linsol(NbrSol)=gp_Lin2d(gp_Pnt2d((C1.Location().XY()).Added(signe*xy)),
167 // =======================================================================
168 gp_Dir2d(-TheLin.Direction().Y(),
169 // =================================
170 TheLin.Direction().X()));
171 // ========================
172 pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY()).Added(signe*xy));
173 IntAna2d_AnaIntersection Intp(linsol(NbrSol),TheLin);
175 if (!Intp.IsEmpty()) {
176 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
177 pntint2sol(NbrSol) = Intp.Point(i).Value();
181 par1sol(NbrSol) = ElCLib::Parameter(linsol(NbrSol),pnttg1sol(NbrSol));
182 par2sol(NbrSol) = ElCLib::Parameter(linsol(NbrSol),pntint2sol(NbrSol));
183 pararg1(NbrSol) = ElCLib::Parameter(C1,pnttg1sol(NbrSol));
184 pararg2(NbrSol) = ElCLib::Parameter(TheLin,pntint2sol(NbrSol));
185 WellDone = Standard_True;
189 //=========================================================================
190 // Straight line tangent to circle : Qualified1 (C1) +
191 // and orthogonal to circle : TheCircle. +
192 // Create straight line of origin : P1 (on C1) +
193 // and direction : TheLin.Direction() turned by 90` +
194 //=========================================================================
197 GccAna_Lin2dTanPer (const GccEnt_QualifiedCirc& Qualified1,
198 const gp_Circ2d& TheCircle ):
209 WellDone = Standard_False;
211 Standard_Integer signe = 0;
212 gp_Circ2d C1 = Qualified1.Qualified();
214 if (Qualified1.IsEnclosed()) {
215 // ============================
216 GccEnt_BadQualifier::Raise();
218 else if (Qualified1.IsEnclosing()) {
219 // ==================================
221 qualifier1(1) = GccEnt_enclosing;
223 else if (Qualified1.IsOutside()) {
224 // ================================
226 qualifier1(1) = GccEnt_outside;
228 else if (Qualified1.IsUnqualified()) {
229 // ====================================
231 qualifier1(1) = GccEnt_enclosing;
232 qualifier1(2) = GccEnt_outside;
234 for (Standard_Integer j = 1 ; j <= 2 ; j++) {
237 gp_Dir2d D1(TheCircle.Location().XY()-C1.Location().XY());
238 linsol(NbrSol) = gp_Lin2d(gp_Pnt2d((C1.Location().XY())+
239 // ===================================================
240 signe*(D1.XY()*C1.Radius())),gp_Dir2d(-D1.Y(),D1.X()));
241 // ======================================================
242 pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY())+
243 signe*(D1.XY()*C1.Radius()));
244 IntAna2d_AnaIntersection Intp(linsol(NbrSol),TheCircle);
246 if (!Intp.IsEmpty()) {
247 Standard_Real maxdist = RealLast();
248 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
249 if (Intp.Point(i).Value().Distance(pnttg1sol(NbrSol)) < maxdist) {
250 pntint2sol(NbrSol) = Intp.Point(i).Value();
255 par1sol(NbrSol) = ElCLib::Parameter(linsol(NbrSol),pnttg1sol(NbrSol));
256 par2sol(NbrSol) = ElCLib::Parameter(linsol(NbrSol),pntint2sol(NbrSol));
257 pararg1(NbrSol) = ElCLib::Parameter(C1,pnttg1sol(NbrSol));
258 pararg2(NbrSol) = ElCLib::Parameter(TheCircle,pntint2sol(NbrSol));
259 WellDone = Standard_True;
263 Standard_Boolean GccAna_Lin2dTanPer::
264 IsDone () const { return WellDone; }
266 Standard_Integer GccAna_Lin2dTanPer::
269 if (!WellDone) { StdFail_NotDone::Raise(); }
273 gp_Lin2d GccAna_Lin2dTanPer::
274 ThisSolution (const Standard_Integer Index) const
276 if (!WellDone) { StdFail_NotDone::Raise(); }
277 if (Index <= 0 || Index > NbrSol) { Standard_RangeError::Raise(); }
278 return linsol(Index);
281 void GccAna_Lin2dTanPer::
282 WhichQualifier(const Standard_Integer Index ,
283 GccEnt_Position& Qualif1 ) const
285 if (!WellDone) { StdFail_NotDone::Raise(); }
286 if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
288 Qualif1 = qualifier1(Index);
292 void GccAna_Lin2dTanPer::
293 Tangency1 (const Standard_Integer Index,
294 Standard_Real& ParSol,
295 Standard_Real& ParArg,
296 gp_Pnt2d& Pnt) const{
297 if (!WellDone) { StdFail_NotDone::Raise(); }
298 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
300 ParSol = par1sol(Index);
301 ParArg = pararg1(Index);
302 Pnt = gp_Pnt2d(pnttg1sol(Index));
306 void GccAna_Lin2dTanPer::
307 Intersection2 (const Standard_Integer Index,
308 Standard_Real& ParSol,
309 Standard_Real& ParArg,
310 gp_Pnt2d& PntSol) const {
311 if (!WellDone) { StdFail_NotDone::Raise(); }
312 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
314 ParSol = par2sol(Index);
315 ParArg = pararg2(Index);
316 PntSol = gp_Pnt2d(pntint2sol(Index));