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 #include <Geom2dGcc_Circ2dTanCenGeo.ixx>
17 #include <StdFail_NotDone.hxx>
18 #include <Standard_OutOfRange.hxx>
19 #include <Standard_Failure.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>
27 #include <Geom2dGcc_CurveTool.hxx>
28 #include <Extrema_ExtPC2d.hxx>
30 //=========================================================================
31 // Creation d un cercle tangent a une courbe centre en un point. +
32 //=========================================================================
34 Geom2dGcc_Circ2dTanCenGeo::
35 Geom2dGcc_Circ2dTanCenGeo (const Geom2dGcc_QCurve& Qualified1,
36 const gp_Pnt2d& Pcenter ,
37 const Standard_Real Tolerance ):
39 //========================================================================
40 // Initialisation des champs. +
41 //========================================================================
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();
56 Standard_Integer i = 1;
57 Standard_Integer nbsol = 0;
58 gp_Dir2d dirx(1.0,0.0);
60 Geom2dAdaptor_Curve curve = Qualified1.Qualified();
61 Extrema_ExtPC2d distmin(Pcenter,curve,Geom2dGcc_CurveTool::NbSamples(curve),
62 Geom2dGcc_CurveTool::EpsX(curve,Tol),Tol);
63 if (!distmin.IsDone() ) { Standard_Failure::Raise(); }
64 Standard_Integer nbext = distmin.NbExt();
65 if(nbext==0) { Standard_Failure::Raise(); }
67 thePar = distmin.Point(i).Parameter();
68 if (distmin.SquareDistance(i)<theDist2(1) &&
69 thePar>=Geom2dGcc_CurveTool::FirstParameter(curve) &&
70 thePar <= Geom2dGcc_CurveTool::LastParameter(curve)) {
71 theDist2(1) = distmin.SquareDistance(i);
73 pTan(1) = distmin.Point(i).Value();
75 if (distmin.SquareDistance(i)>theDist2(2) &&
76 thePar>=Geom2dGcc_CurveTool::FirstParameter(curve) &&
77 thePar <= Geom2dGcc_CurveTool::LastParameter(curve)) {
78 theDist2(2) = distmin.SquareDistance(i);
80 pTan(2) = distmin.Point(i).Value();
84 if (Index(1) == Index(2)) { nbsol = 1; }
86 for (i = 1 ; i <= nbsol; i++) {
89 Geom2dGcc_CurveTool::D1(curve,theParam(i),point1,Tan1);
90 Standard_Real normetan1 = Tan1.Magnitude();
91 gp_Vec2d Vec1(point1,Pcenter);
92 Standard_Real normevec1 = Vec1.Magnitude();
94 if (normevec1 >= gp::Resolution() && normetan1 >= gp::Resolution()) {
95 dot1 = Vec1.Dot(Tan1)/(normevec1*normetan1);
100 Standard_Real Angle1 = Vec1.Angle(Tan1);
101 if (Qualified1.IsUnqualified()||
102 (Qualified1.IsEnclosing()&&Angle1<=0.)||
103 (Qualified1.IsOutside() && Angle1 >= 0.) ||
104 (Qualified1.IsEnclosed() && Angle1 <= 0.)) {
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;
119 //=========================================================================
122 Standard_Boolean Geom2dGcc_Circ2dTanCenGeo::
123 IsDone () const { return WellDone; }
125 Standard_Integer Geom2dGcc_Circ2dTanCenGeo::
126 NbSolutions () const { return NbrSol; }
128 gp_Circ2d Geom2dGcc_Circ2dTanCenGeo::
129 ThisSolution (const Standard_Integer Index) const
131 if (Index > NbrSol || Index <= 0) Standard_OutOfRange::Raise();
133 return cirsol(Index);
136 void Geom2dGcc_Circ2dTanCenGeo::
137 WhichQualifier(const Standard_Integer Index ,
138 GccEnt_Position& Qualif1 ) const
140 if (!WellDone) { StdFail_NotDone::Raise(); }
141 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
143 Qualif1 = qualifier1(Index);
147 void Geom2dGcc_Circ2dTanCenGeo::
148 Tangency1 (const Standard_Integer Index,
149 Standard_Real& ParSol,
150 Standard_Real& ParArg,
151 gp_Pnt2d& PntSol) const{
153 StdFail_NotDone::Raise();
155 else if (Index <= 0 ||Index > NbrSol) {
156 Standard_OutOfRange::Raise();
159 PntSol = gp_Pnt2d(pnttg1sol(Index));
160 ParSol = par1sol(Index);
161 ParArg = pararg1(Index);