summaryrefslogtreecommitdiff
path: root/inc/GccIter_Lin2dTanObl.gxx
blob: c6ae864852d5084179f832075da9f7b39a7557ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// File:	GccIter_Lin2dTanObl.cxx
// Created:	Fri Dec 20 15:00:23 1991
// Author:	Remi GILET
//		<reg@topsn3>

//========================================================================
// CREATION D UNE LIGNE TANGENTE A UNE COURBE ET PARALLELE A UNE DROITE. +
//========================================================================

#include <IntAna2d_AnaIntersection.hxx>
#include <IntAna2d_IntPoint.hxx>
#include <GccIter_IsParallel.hxx>
#include <StdFail_NotDone.hxx>
#include <GccEnt_BadQualifier.hxx>
#include <math_FunctionRoot.hxx>
#include <gp_XY.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Vec2d.hxx>
#include <gp_Circ2d.hxx>

GccIter_Lin2dTanObl::
   GccIter_Lin2dTanObl (const TheQualifiedCurve& Qualified1 ,
			const gp_Lin2d&          TheLin     ,
			const Standard_Real      Param1     ,
			const Standard_Real      TolAng     ,
			const Standard_Real      Angle      ) {

   par1sol = 0.;
   pararg1 = 0.;
   WellDone = Standard_False;
   if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || 
	 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
     GccEnt_BadQualifier::Raise();
     return;
   }
   Paral2 = Standard_False;
   TheCurve Cu1 = Qualified1.Qualified();
   Standard_Real U1 = TheCurveTool::FirstParameter(Cu1);
   Standard_Real U2 = TheCurveTool::LastParameter(Cu1);
   gp_Dir2d Dir(TheLin.Direction());
   Standard_Real A = Dir.X();
   Standard_Real B = Dir.Y();
   gp_Dir2d TheDirection(Dir);
   if (Abs(Angle) > Abs(TolAng)) {
     if (Abs(Abs(Angle)-PI) <= Abs(TolAng)) {
       Paral2 = Standard_True;
       TheDirection = Dir.Reversed();
     }
     else if (Abs(Angle-PI/2) <= Abs(TolAng)) { TheDirection=gp_Dir2d(-B,A); }
     else if (Abs(Angle+PI/2) <= Abs(TolAng)) { TheDirection=gp_Dir2d(B,-A); }
     else {
       TheDirection=gp_Dir2d(A*Cos(Angle)-B*Sin(Angle),
			     A*Sin(Angle)+B*Cos(Angle));
     }
   }
   else { Paral2 = Standard_True; }
   GccIter_FuncTObl func(Cu1,TheDirection);
   math_FunctionRoot sol(func,Param1,
			 TheCurveTool::EpsX(Cu1,Abs(TolAng)),U1,U2,100);
   if (sol.IsDone()) {
     Standard_Real Usol = sol.Root();
     gp_Pnt2d Origine;
     gp_Vec2d Vect1,Vect2;
     TheCurveTool::D2(Cu1,Usol,Origine,Vect1,Vect2);
     Standard_Real sign1 = Vect1.XY().Dot(TheDirection.XY());
     Standard_Real sign2 = Vect2.XY().Crossed(TheDirection.XY());
     if (Qualified1.IsUnqualified() || 
	 (Qualified1.IsEnclosing() && sign2<=0.) ||
	 (Qualified1.IsOutside() && sign1 <= 0. && sign2 >= 0.) ||
	 (Qualified1.IsEnclosed() && sign1 >= 0. && sign2 >= 0.)) {
       WellDone = Standard_True;
       linsol = gp_Lin2d(Origine,TheDirection);
       pnttg1sol = Origine;
       qualifier1 = Qualified1.Qualifier();
       pararg1 = Usol;
       par1sol = 0.;
       if (!Paral2) {
	 IntAna2d_AnaIntersection Intp(linsol,TheLin);
	 if (Intp.IsDone() && !Intp.IsEmpty()) {
	   if (Intp.NbPoints()==1) {
	     pntint2sol = Intp.Point(1).Value();
	     par2sol = gp_Vec2d(linsol.Direction()).
	       Dot(gp_Vec2d(linsol.Location(),pntint2sol));
	     pararg2 = gp_Vec2d(TheLin.Direction()).
	       Dot(gp_Vec2d(TheLin.Location(),pntint2sol));
	   }
	 }
       }
     }
   }
 }

Standard_Boolean GccIter_Lin2dTanObl::
   IsDone () const { return WellDone; }

gp_Lin2d GccIter_Lin2dTanObl::ThisSolution () const 
{	
  if (!WellDone) StdFail_NotDone::Raise();

  return linsol;
}

void GccIter_Lin2dTanObl:: 
  WhichQualifier (GccEnt_Position& Qualif1) const
{
  if (!WellDone) { StdFail_NotDone::Raise(); }
  else {
    Qualif1 = qualifier1;
  }
}

Standard_Boolean GccIter_Lin2dTanObl::
   IsParallel2 () const { return Paral2; }

void GccIter_Lin2dTanObl::
   Tangency1 (Standard_Real& ParSol    ,
              Standard_Real& ParArg    ,
              gp_Pnt2d& PntSol) const {
   if (!WellDone) { StdFail_NotDone::Raise(); }
   else {
     ParSol = par1sol;
     ParArg = pararg1;
     PntSol = gp_Pnt2d(pnttg1sol);
   }
 }

void GccIter_Lin2dTanObl::
  Intersection2 (Standard_Real&     ParSol ,
		 Standard_Real&     ParArg ,
		 gp_Pnt2d& PntSol ) const {
   if (!WellDone) { StdFail_NotDone::Raise(); }
   else if (Paral2) { GccIter_IsParallel::Raise(); }
   else {
     PntSol = pntint2sol;
     ParSol = par2sol;
     ParArg = pararg2;
   }
 }