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.
17 #include <GccAna_Circ2dTanOnRad.hxx>
18 #include <GccEnt_BadQualifier.hxx>
19 #include <GccEnt_QualifiedLin.hxx>
20 #include <gp_Circ2d.hxx>
21 #include <gp_Dir2d.hxx>
22 #include <gp_Lin2d.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <IntAna2d_AnaIntersection.hxx>
25 #include <IntAna2d_IntPoint.hxx>
26 #include <Standard_NegativeValue.hxx>
27 #include <TColStd_Array1OfInteger.hxx>
29 //=========================================================================
30 // Circle tangent to straight line Qualified1 (L1) +
31 // center on straight line OnLine +
32 // of radius Radius. +
34 // Initialize the table of solutions cirsol and all fields. +
35 // Elimine depending on the qualifier the cases not being solutions. +
36 // Create L1para : parallel to L1 in the direction required by the +
37 // qualifier at distance Radius. +
38 // Point P of intersection between L1para and OnLine will give the center point +
40 // Create solutions cirsol with center P and radius Radius. +
42 //=========================================================================
43 GccAna_Circ2dTanOnRad::
44 GccAna_Circ2dTanOnRad (const GccEnt_QualifiedLin& Qualified1,
45 const gp_Lin2d& OnLine ,
46 const Standard_Real Radius ,
47 const Standard_Real Tolerance ):
58 Standard_Real Tol =Abs(Tolerance);
59 gp_Dir2d dirx(1.0,0.0);
60 WellDone = Standard_False;
62 if (!(Qualified1.IsEnclosed() ||
63 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
64 throw GccEnt_BadQualifier();
67 Standard_Integer nbsol = 0;
68 TColStd_Array1OfInteger eps(1,2);
69 gp_Lin2d L1 = Qualified1.Qualified();
70 gp_Pnt2d origin1(L1.Location());
71 gp_Dir2d dir1(L1.Direction());
72 gp_Dir2d normL1(-dir1.Y(),dir1.X());
74 if (Radius < 0.0) { throw Standard_NegativeValue(); }
75 else if ((OnLine.Direction()).IsParallel(dir1,Tol)) {
76 WellDone = Standard_True;
79 if (Qualified1.IsEnclosed()) {
80 // ============================
84 else if (Qualified1.IsOutside()) {
85 // ================================
95 Standard_Real dx1 = dir1.X();
96 Standard_Real dy1 = dir1.Y();
97 Standard_Real lx1 = origin1.X();
98 Standard_Real ly1 = origin1.Y();
99 for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
100 gp_Lin2d L1para(gp_Pnt2d(lx1+eps(j)*Radius*dy1,ly1-eps(j)*Radius*dx1),
102 IntAna2d_AnaIntersection Intp(OnLine,L1para);
104 if (!Intp.IsEmpty()) {
105 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
107 gp_Pnt2d Center(Intp.Point(i).Value());
108 cirsol(NbrSol)=gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
109 // =====================================================
110 gp_Dir2d dc1(origin1.XY()-Center.XY());
111 if (!Qualified1.IsUnqualified()) {
112 qualifier1(NbrSol) = Qualified1.Qualifier();
114 else if (dc1.Dot(normL1) > 0.0) {
115 qualifier1(NbrSol) = GccEnt_outside;
117 else { qualifier1(NbrSol) = GccEnt_enclosed; }
118 TheSame1(NbrSol) = 0;
119 if (gp_Vec2d(Center,origin1).Dot(gp_Dir2d(-dy1,dx1))>0.0) {
120 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius*gp_XY(-dy1,dx1));
121 pntcen3(NbrSol) = cirsol(1).Location();
124 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()-Radius*gp_XY(-dy1,dx1));
125 pntcen3(NbrSol) = cirsol(1).Location();
127 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
129 pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
130 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen3(NbrSol));
133 WellDone = Standard_True;