Integration of OCCT 6.5.0 from SVN
[occt.git] / src / GccAna / GccAna_Circ2dTanOnRad_1.cxx
CommitLineData
7fd59977 1// file GccAna_Circ2dTanOnRad_1.cxx, REG 08/07/91
2
3#include <GccAna_Circ2dTanOnRad.jxx>
4
5#include <ElCLib.hxx>
6#include <IntAna2d_AnaIntersection.hxx>
7#include <IntAna2d_IntPoint.hxx>
8#include <TColStd_Array1OfInteger.hxx>
9#include <Standard_NegativeValue.hxx>
10#include <gp_Dir2d.hxx>
11#include <Standard_OutOfRange.hxx>
12#include <GccEnt_BadQualifier.hxx>
13
14//=========================================================================
15// Cercle tangent a une droite Qualified1 (L1) +
16// centre sur une droite OnLine +
17// de rayon Radius. +
18// +
19// On initialise le tableau de solutions cirsol ainsi que tous les +
20// champs. +
21// On elimine en fonction du qualifieur les cas ne presentant pas de +
22// solutions. +
23// On cree L1para : la parallele a L1 dans le sens voulu par le +
24// qualifieur a une distance Radius. +
25// Le point P d intersection entre L1para et OnLine donnera le point de +
26// centre de la solution. +
27// On cree les solutions cirsol de centre P et de rayon Radius. +
28// On remplit les champs. +
29//=========================================================================
30
31GccAna_Circ2dTanOnRad::
32 GccAna_Circ2dTanOnRad (const GccEnt_QualifiedLin& Qualified1,
33 const gp_Lin2d& OnLine ,
34 const Standard_Real Radius ,
35 const Standard_Real Tolerance ):
36 cirsol(1,2) ,
37 qualifier1(1,2) ,
38 TheSame1(1,2) ,
39 pnttg1sol(1,2) ,
40 pntcen3(1,2) ,
41 par1sol(1,2) ,
42 pararg1(1,2) ,
43 parcen3(1,2)
44{
45
46 Standard_Real Tol =Abs(Tolerance);
47 gp_Dir2d dirx(1.0,0.0);
48 WellDone = Standard_False;
49 NbrSol = 0;
50 if (!(Qualified1.IsEnclosed() ||
51 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
52 GccEnt_BadQualifier::Raise();
53 return;
54 }
55 Standard_Integer nbsol = 0;
56 TColStd_Array1OfInteger eps(1,2);
57 gp_Lin2d L1 = Qualified1.Qualified();
58 gp_Pnt2d origin1(L1.Location());
59 gp_Dir2d dir1(L1.Direction());
60 gp_Dir2d normL1(-dir1.Y(),dir1.X());
61
62 if (Radius < 0.0) { Standard_NegativeValue::Raise(); }
63 else if ((OnLine.Direction()).IsParallel(dir1,Tol)) {
64 WellDone = Standard_True;
65 }
66 else {
67 if (Qualified1.IsEnclosed()) {
68// ============================
69 eps(1) = -1;
70 nbsol = 1;
71 }
72 else if (Qualified1.IsOutside()) {
73// ================================
74 eps(1) = 1;
75 nbsol = 1;
76 }
77 else {
78// ====
79 eps(1) = 1;
80 eps(2) = -1;
81 nbsol = 2;
82 }
83 Standard_Real dx1 = dir1.X();
84 Standard_Real dy1 = dir1.Y();
85 Standard_Real lx1 = origin1.X();
86 Standard_Real ly1 = origin1.Y();
87 for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
88 gp_Lin2d L1para(gp_Pnt2d(lx1+eps(j)*Radius*dy1,ly1-eps(j)*Radius*dx1),
89 dir1);
90 IntAna2d_AnaIntersection Intp(OnLine,L1para);
91 if (Intp.IsDone()) {
92 if (!Intp.IsEmpty()) {
93 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
94 NbrSol++;
95 gp_Pnt2d Center(Intp.Point(i).Value());
96 cirsol(NbrSol)=gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
97// =====================================================
98 gp_Dir2d dc1(origin1.XY()-Center.XY());
99#ifdef DEB
100 Standard_Real sign = dc1.Dot(normL1);
101#else
102 dc1.Dot(normL1);
103#endif
104 if (!Qualified1.IsUnqualified()) {
105 qualifier1(NbrSol) = Qualified1.Qualifier();
106 }
107 else if (dc1.Dot(normL1) > 0.0) {
108 qualifier1(NbrSol) = GccEnt_outside;
109 }
110 else { qualifier1(NbrSol) = GccEnt_enclosed; }
111 TheSame1(NbrSol) = 0;
112 if (gp_Vec2d(Center,origin1).Dot(gp_Dir2d(-dy1,dx1))>0.0) {
113 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius*gp_XY(-dy1,dx1));
114 pntcen3(NbrSol) = cirsol(1).Location();
115 }
116 else {
117 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()-Radius*gp_XY(-dy1,dx1));
118 pntcen3(NbrSol) = cirsol(1).Location();
119 }
120 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
121 pnttg1sol(NbrSol));
122 pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
123 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen3(NbrSol));
124 }
125 }
126 WellDone = Standard_True;
127 }
128 }
129 }
130 }