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 LINE TANGENT to a CIRCLE or PASSING by a POINT +
17 // and PARALLEL to a STRAIGHT DROITE. +
18 //========================================================================
21 #include <GccAna_Lin2dTanPar.hxx>
22 #include <GccEnt_BadQualifier.hxx>
23 #include <GccEnt_QualifiedCirc.hxx>
24 #include <gp_Circ2d.hxx>
25 #include <gp_Dir2d.hxx>
26 #include <gp_Lin2d.hxx>
27 #include <gp_Pnt2d.hxx>
28 #include <gp_Vec2d.hxx>
30 #include <Standard_OutOfRange.hxx>
31 #include <StdFail_NotDone.hxx>
33 //========================================================================
34 // Passing by a point : +
35 // Create the straight line with origin ThePoint and +
36 // direction Lin1.Direction(). +
37 //========================================================================
39 GccAna_Lin2dTanPar (const gp_Pnt2d& ThePoint ,
40 const gp_Lin2d& Lin1 ):
48 linsol(1) = gp_Lin2d(ThePoint,Lin1.Direction());
49 // ===============================================
50 qualifier1(1) = GccEnt_noqualifier;
51 pnttg1sol(1) = ThePoint;
55 WellDone = Standard_True;
58 //========================================================================
59 // Tangent to a circle : +
60 // Create following the qualifier the straight line +
61 // - with origin P1 (P1 is a point of intersection between C1 and +
62 // a straight line passing by the center of C1 and +
63 // direction the normal to Lin1). +
64 // the choice of the point of intersection depends +
65 // on the qualifier. +
66 // - with direction the direction of Lin1. +
67 //========================================================================
70 GccAna_Lin2dTanPar (const GccEnt_QualifiedCirc& Qualified1,
71 const gp_Lin2d& Lin1 ):
79 WellDone = Standard_False;
80 Standard_Integer signe = 0;
81 Standard_Integer nbsol = 0;
83 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
84 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
85 throw GccEnt_BadQualifier();
88 gp_Circ2d C1 = Qualified1.Qualified();
89 Standard_Real xdir = (Lin1.Direction()).X();
90 Standard_Real ydir = (Lin1.Direction()).Y();
92 if (Qualified1.IsEnclosed()) { throw GccEnt_BadQualifier(); }
93 // ============================
94 else if (Qualified1.IsEnclosing()) {
95 // ==================================
98 qualifier1(1) = GccEnt_enclosing;
100 else if (Qualified1.IsOutside()) {
101 // ===================================
104 qualifier1(1) = GccEnt_outside;
109 qualifier1(1) = GccEnt_outside;
110 qualifier1(2) = GccEnt_enclosing;
112 gp_XY xy(-C1.Radius()*ydir,C1.Radius()*xdir);
113 for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
116 linsol(NbrSol) = gp_Lin2d(gp_Pnt2d((C1.Location().XY()).Added(signe*xy)),
117 // =========================================================================
120 pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY()).Added(signe*xy));
121 par1sol(NbrSol) = 0.;
122 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
123 WellDone = Standard_True;
127 Standard_Boolean GccAna_Lin2dTanPar::
128 IsDone () const { return WellDone; }
130 Standard_Integer GccAna_Lin2dTanPar::NbSolutions () const
133 throw StdFail_NotDone();
137 gp_Lin2d GccAna_Lin2dTanPar::ThisSolution (const Standard_Integer Index) const
139 if (!WellDone) { throw StdFail_NotDone(); }
140 else if (Index <= 0 || Index > NbrSol) { throw Standard_OutOfRange(); }
141 return linsol(Index);
144 void GccAna_Lin2dTanPar::
145 WhichQualifier(const Standard_Integer Index ,
146 GccEnt_Position& Qualif1 ) const
148 if (!WellDone) { throw StdFail_NotDone(); }
149 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
151 Qualif1 = qualifier1(Index);
155 void GccAna_Lin2dTanPar::
156 Tangency1 (const Standard_Integer Index,
157 Standard_Real& ParSol,
158 Standard_Real& ParArg,
159 gp_Pnt2d& Pnt) const {
160 if (!WellDone) { throw StdFail_NotDone(); }
161 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
163 ParSol = par1sol(Index);
164 ParArg = pararg1(Index);
165 Pnt = gp_Pnt2d(pnttg1sol(Index));