summaryrefslogtreecommitdiff
path: root/inc/GccIter_Lin2d2Tan.gxx
blob: 779a42800ab2bd1a302c9271c73d5e53e6d3e180 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// File:	GccIter_Lin2d2Tan.gxx
// Created:	Fri Dec 20 15:00:23 1991
// Author:	Remi GILET
//		<reg@topsn3>

//========================================================================
//  CREATION D UNE LIGNE TANGENTE A DEUX COURBES.                        +
//========================================================================

#include <StdFail_NotDone.hxx>
#include <GccEnt_BadQualifier.hxx>
#include <gp_XY.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Vec2d.hxx>
#include <gp_Circ2d.hxx>
#include <math_Vector.hxx>
#include <math_Matrix.hxx>
#include <math_FunctionSetRoot.hxx>
#include <math_FunctionRoot.hxx>

GccIter_Lin2d2Tan::
   GccIter_Lin2d2Tan (const GccEnt_QualifiedCirc& Qualified1 ,
		      const TheQualifiedCurve&    Qualified2 ,
		      const Standard_Real         Param2     ,
		      const Standard_Real         Tolang     ) {
     
   par1sol = 0.;
   pararg1 = 0.;
   WellDone = Standard_False;
   if (Qualified1.IsEnclosed()) { GccEnt_BadQualifier::Raise(); }
   gp_Circ2d C1 = Qualified1.Qualified();
   TheCurve Cu2 = Qualified2.Qualified();
   Standard_Real U1 = TheCurveTool::FirstParameter(Cu2);
   Standard_Real U2 = TheCurveTool::LastParameter(Cu2);
   GccIter_FuncTCirCu func(C1,Cu2);
   math_FunctionRoot sol(func,Param2,TheCurveTool::EpsX(Cu2,Abs(Tolang)),U1,U2,100);
   if (sol.IsDone()) {
     Standard_Real Usol = sol.Root();
//     gp_Pnt2d Origine,Pt;
//  Modified by Sergey KHROMOV - Thu Apr  5 17:39:47 2001 Begin
     Standard_Real Norm;
     func.Value(Usol, Norm);
     if (Abs(Norm) < Tolang) {
//  Modified by Sergey KHROMOV - Thu Apr  5 17:39:48 2001 End
     gp_Pnt2d Origine;
     gp_Vec2d Vect1;
     gp_Vec2d Vect2;
     TheCurveTool::D2(Cu2,Usol,Origine,Vect1,Vect2);
     gp_Vec2d Vdir(C1.Location().XY() - Origine.XY());
     Standard_Real sign1 = Vect1.Dot(Vdir);
     if (sign1 <= 0. ) { Vect1.Reverse(); }
     Standard_Real sign2 = Vect2.Crossed(Vect1);
     if (Qualified2.IsUnqualified() || 
	 (Qualified2.IsEnclosing() && sign2<=0.) ||
	 (Qualified2.IsOutside() && sign1 <= 0. && sign2 >= 0.) ||
	 (Qualified2.IsEnclosed() && sign1 >= 0. && sign2 >= 0.)) {
       if (Qualified1.IsUnqualified() ||
	   (Qualified1.IsOutside() && Vect1.Angle(Vdir) <= 0.) ||
	   (Qualified1.IsEnclosing() && Vect1.Angle(Vdir) >= 0.)) {
	 gp_Dir2d direc(Vect1);
	 Standard_Real R1 = C1.Radius();
	 gp_XY normal(-R1*direc.Y(),R1*direc.X());
	 sign1 = Vect1.Crossed(Vdir);
	 if (Qualified1.IsEnclosing()) {
	   pnttg1sol = gp_Pnt2d(C1.Location().XY()-normal);
	 }
	 else if (Qualified1.IsOutside()) {
	   pnttg1sol = gp_Pnt2d(C1.Location().XY()+normal);
	 }
	 else {
	   if (sign1 >= 0.) {
	     pnttg1sol = gp_Pnt2d(C1.Location().XY()-normal);
	   }
	   else {
	     pnttg1sol = gp_Pnt2d(C1.Location().XY()+normal);
	   }
	 }
// 	 if (gp_Vec2d(direc.XY()).Angle(gp_Vec2d(pnttg1sol,Origine)) <= Tol) {
	   pnttg2sol = Origine;
	   linsol = gp_Lin2d(pnttg1sol,direc);
	   WellDone = Standard_True;
	   qualifier1 = Qualified1.Qualifier();
	   qualifier2 = Qualified2.Qualifier();
	   pararg2 = Usol;
	   par1sol = 0.;
	   par2sol = pnttg2sol.Distance(pnttg1sol);
	   pararg1 = 0.;
	 }
       }
     }
   }
 }

GccIter_Lin2d2Tan::
   GccIter_Lin2d2Tan (const TheQualifiedCurve& Qualified1 ,
		      const TheQualifiedCurve& Qualified2 ,
		      const Standard_Real      Param1     ,
		      const Standard_Real      Param2     ,
		      const Standard_Real      Tolang     ) {
   par1sol = 0.;
   pararg1 = 0.;
   WellDone = Standard_False;
   if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || 
	 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
       !(Qualified2.IsEnclosed() || Qualified2.IsEnclosing() || 
	 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
     GccEnt_BadQualifier::Raise();
     return;
   }
   TheCurve Cu1 = Qualified1.Qualified();
   TheCurve Cu2 = Qualified2.Qualified();
   GccIter_FuncTCuCu Func(Cu1,Cu2);
   math_Vector Umin(1,2);
   math_Vector Umax(1,2);
   math_Vector Ufirst(1,2);
   math_Vector tol(1,2);
   Umin(1) = TheCurveTool::FirstParameter(Cu1);
   Umin(2) = TheCurveTool::FirstParameter(Cu2);
   Umax(1) = TheCurveTool::LastParameter(Cu1);
   Umax(2) = TheCurveTool::LastParameter(Cu2);
   Ufirst(1) = Param1;
   Ufirst(2) = Param2;
   tol(1) = TheCurveTool::EpsX(Cu1,Abs(Tolang));
   tol(2) = TheCurveTool::EpsX(Cu2,Abs(Tolang));
   math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
   if (Root.IsDone()) {
     Root.Root(Ufirst);
//  Modified by Sergey KHROMOV - Thu Apr  5 17:45:00 2001 Begin
     math_Vector Norm(1,2);
     Func.Value(Ufirst, Norm);
     if (Abs(Norm(1)) < Tolang && Abs(Norm(2)) < Tolang) {
//  Modified by Sergey KHROMOV - Thu Apr  5 17:45:01 2001 End
       gp_Pnt2d point1,point2;
       gp_Vec2d Vect11,Vect12,Vect21,Vect22;
       TheCurveTool::D2(Cu1,Ufirst(1),point1,Vect11,Vect12);
       TheCurveTool::D2(Cu2,Ufirst(2),point2,Vect21,Vect22);
       gp_Vec2d Vec(point1.XY(),point2.XY());
       Standard_Real Angle1 = Vec.Angle(Vect12);
       Standard_Real sign1 = Vect11.Dot(Vec);
       if (Qualified1.IsUnqualified() || 
	   (Qualified1.IsEnclosing() && Angle1 >= 0.) ||
	   (Qualified1.IsOutside() && Angle1 <= 0. && sign1 <= 0.) ||
	   (Qualified1.IsEnclosed() && Angle1 <= 0. && sign1 >= 0.)) {
	 Angle1 = Vec.Angle(Vect22);
	 sign1 = Vect21.Dot(Vec);
	 if (Qualified2.IsUnqualified() || 
	     (Qualified2.IsEnclosing() && Angle1 >= 0.) ||
	     (Qualified2.IsOutside() && Angle1 <= 0. && sign1 <= 0.) ||
	     (Qualified2.IsEnclosed() && Angle1 <= 0. && sign1 >= 0.)) {
	   qualifier1 = Qualified1.Qualifier();
	   qualifier2 = Qualified2.Qualifier();
	   pararg1 = Ufirst(1);
	   par1sol = 0.;
	   pnttg1sol = point1;
	   pararg2 = Ufirst(2);
	   pnttg2sol = point2;
	   par2sol = pnttg2sol.Distance(pnttg1sol);
	   gp_Dir2d dir(pnttg2sol.X()-pnttg1sol.X(),pnttg2sol.Y()-pnttg1sol.Y());
	   linsol = gp_Lin2d(pnttg1sol,dir);
	   WellDone = Standard_True;
	 }
       }
     }
   }
 }

GccIter_Lin2d2Tan::
   GccIter_Lin2d2Tan (const TheQualifiedCurve& Qualified1 ,
		      const gp_Pnt2d&          ThePoint   ,
		      const Standard_Real      Param1     ,
		      const Standard_Real      Tolang     ) {
     
   par1sol = 0.;
   pararg1 = 0.;
   WellDone = Standard_False;
   if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || 
	 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
     GccEnt_BadQualifier::Raise();
     return;
   }
   TheCurve Cu1 = Qualified1.Qualified();
   Standard_Real U1 = TheCurveTool::FirstParameter(Cu1);
   Standard_Real U2 = TheCurveTool::LastParameter(Cu1);
   GccIter_FuncTCuPt func(Cu1,ThePoint);
   math_FunctionRoot sol(func,Param1,TheCurveTool::EpsX(Cu1,Abs(Tolang)),U1,U2,100);
   if (sol.IsDone()) {
     Standard_Real Usol = sol.Root();
//  Modified by Sergey KHROMOV - Thu Apr  5 17:45:17 2001 Begin
     Standard_Real Norm;
     func.Value(Usol, Norm);
     if (Abs(Norm) < Tolang) {
//  Modified by Sergey KHROMOV - Thu Apr  5 17:45:19 2001 End
       gp_Pnt2d Origine;
       gp_Vec2d Vect1;
       gp_Vec2d Vect2;
       TheCurveTool::D2(Cu1,Usol,Origine,Vect1,Vect2);
       gp_Vec2d Vdir(ThePoint.XY()-Origine.XY());
       Standard_Real sign1 = Vect1.Dot(Vdir);
       Standard_Real sign2 = Vect2.Crossed(Vdir);
       if (Qualified1.IsUnqualified() || 
	   (Qualified1.IsEnclosing() && 
	    ((sign1 >= 0. && sign2 <= 0.) || (sign1 <= 0. && sign2 <= 0.))) ||
	   (Qualified1.IsOutside() && sign1 <= 0. && sign2 >= 0.) ||
	   (Qualified1.IsEnclosed() && sign1 >= 0. && sign2 >= 0.)) {
	 WellDone = Standard_True;
	 linsol = gp_Lin2d(Origine,gp_Dir2d(Vdir));
	 qualifier1 = Qualified1.Qualifier();
	 qualifier2 = GccEnt_noqualifier;
	 pnttg1sol = Origine;
	 pnttg2sol = ThePoint;
	 pararg1 = Usol;
	 par1sol = 0.;
	 pararg2 = ThePoint.Distance(Origine);
	 par2sol = 0.;
       }
     }
   }
 }

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

gp_Lin2d GccIter_Lin2d2Tan::
   ThisSolution () const 
{
  if (!WellDone) StdFail_NotDone::Raise();
  return linsol;
}

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

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

void GccIter_Lin2d2Tan::
   Tangency2 (Standard_Real& ParSol ,
              Standard_Real& ParArg ,
              gp_Pnt2d& Pnt) const {
   if (!WellDone) { StdFail_NotDone::Raise(); }
   else {
     ParSol = par2sol;
     ParArg = pararg2;
     Pnt    = pnttg2sol;
   }
 }