1 // File GccAna_Lin2dTanPar.cxx, REG 08/07/91
3 //========================================================================
4 // CREATION of a LINE TANGENT to a CIRCLE or PASSING by a POINT +
5 // and PARALLEL to a STRAIGHT DROITE. +
6 //========================================================================
8 #include <GccAna_Lin2dTanPar.ixx>
11 #include <StdFail_NotDone.hxx>
13 #include <gp_Dir2d.hxx>
14 #include <gp_Vec2d.hxx>
15 #include <gp_Circ2d.hxx>
16 #include <Standard_OutOfRange.hxx>
17 #include <GccEnt_BadQualifier.hxx>
19 //========================================================================
20 // Passing by a point : +
21 // Create the straight line with origin ThePoint and +
22 // direction Lin1.Direction(). +
23 //========================================================================
26 GccAna_Lin2dTanPar (const gp_Pnt2d& ThePoint ,
27 const gp_Lin2d& Lin1 ):
35 linsol(1) = gp_Lin2d(ThePoint,Lin1.Direction());
36 // ===============================================
37 qualifier1(1) = GccEnt_noqualifier;
38 pnttg1sol(1) = ThePoint;
42 WellDone = Standard_True;
45 //========================================================================
46 // Tangent to a circle : +
47 // Create following the qualifier the straight line +
48 // - with origin P1 (P1 is a point of intersection between C1 and +
49 // a straight line passing by the center of C1 and +
50 // direction the normal to Lin1). +
51 // the choice of the point of intersection depends +
52 // on the qualifier. +
53 // - with direction the direction of Lin1. +
54 //========================================================================
57 GccAna_Lin2dTanPar (const GccEnt_QualifiedCirc& Qualified1,
58 const gp_Lin2d& Lin1 ):
66 WellDone = Standard_False;
67 Standard_Integer signe = 0;
68 Standard_Integer nbsol = 0;
70 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
71 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
72 GccEnt_BadQualifier::Raise();
75 gp_Circ2d C1 = Qualified1.Qualified();
76 Standard_Real xdir = (Lin1.Direction()).X();
77 Standard_Real ydir = (Lin1.Direction()).Y();
79 if (Qualified1.IsEnclosed()) { GccEnt_BadQualifier::Raise(); }
80 // ============================
81 else if (Qualified1.IsEnclosing()) {
82 // ==================================
85 qualifier1(1) = GccEnt_enclosing;
87 else if (Qualified1.IsOutside()) {
88 // ===================================
91 qualifier1(1) = GccEnt_outside;
96 qualifier1(1) = GccEnt_outside;
97 qualifier1(2) = GccEnt_enclosing;
99 gp_XY xy(-C1.Radius()*ydir,C1.Radius()*xdir);
100 for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
103 linsol(NbrSol) = gp_Lin2d(gp_Pnt2d((C1.Location().XY()).Added(signe*xy)),
104 // =========================================================================
107 pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY()).Added(signe*xy));
108 par1sol(NbrSol) = 0.;
109 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
110 WellDone = Standard_True;
114 Standard_Boolean GccAna_Lin2dTanPar::
115 IsDone () const { return WellDone; }
117 Standard_Integer GccAna_Lin2dTanPar::NbSolutions () const
120 StdFail_NotDone::Raise();
124 gp_Lin2d GccAna_Lin2dTanPar::ThisSolution (const Standard_Integer Index) const
126 if (!WellDone) { StdFail_NotDone::Raise(); }
127 else if (Index <= 0 || Index > NbrSol) { Standard_OutOfRange::Raise(); }
128 return linsol(Index);
131 void GccAna_Lin2dTanPar::
132 WhichQualifier(const Standard_Integer Index ,
133 GccEnt_Position& Qualif1 ) const
135 if (!WellDone) { StdFail_NotDone::Raise(); }
136 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
138 Qualif1 = qualifier1(Index);
142 void GccAna_Lin2dTanPar::
143 Tangency1 (const Standard_Integer Index,
144 Standard_Real& ParSol,
145 Standard_Real& ParArg,
146 gp_Pnt2d& Pnt) const {
147 if (!WellDone) { StdFail_NotDone::Raise(); }
148 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
150 ParSol = par1sol(Index);
151 ParArg = pararg1(Index);
152 Pnt = gp_Pnt2d(pnttg1sol(Index));