summaryrefslogtreecommitdiff
path: root/inc/ApproxInt_PrmPrmSvSurfaces.gxx
blob: 1b8f595c78d2c623177908df03a319504f7b5ca0 (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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// File:	ApproxInt_PrmPrmSvSurfaces.gxx
// Created:	Wed Mar 17 12:42:28 1993
// Author:	Laurent BUCHARD
//		<lbr@topsn3>

#define TOLTANGENCY 0.0000000001


#include <TColStd_Array1OfReal.hxx>
#include <math_FunctionSetRoot.hxx>

#define Debug(expr)  cout<<" expr :"<<expr;
#define MySurf1 MyIntersectionOn2S.Function().AuxillarSurface1()
#define MySurf2 MyIntersectionOn2S.Function().AuxillarSurface2()


//--------------------------------------------------------------------------------
ApproxInt_PrmPrmSvSurfaces::ApproxInt_PrmPrmSvSurfaces( const ThePSurface& Surf1
						       ,const ThePSurface& Surf2):
       MyHasBeenComputed(Standard_False),
       MyHasBeenComputedbis(Standard_False),
       MyIntersectionOn2S(Surf1,Surf2,TOLTANGENCY)
{ 
}
//--------------------------------------------------------------------------------
Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Compute( Standard_Real& u1
						     ,Standard_Real& v1
						     ,Standard_Real& u2
						     ,Standard_Real& v2
						     ,gp_Pnt& P
						     ,gp_Vec& Tg
						     ,gp_Vec2d& Tguv1
						     ,gp_Vec2d& Tguv2) { 
  
  Standard_Real tu1=u1;
  Standard_Real tu2=u2;
  Standard_Real tv1=v1;
  Standard_Real tv2=v2;
  
  if(MyHasBeenComputed) { 
    if(  (MyParOnS1.X()==u1)&&(MyParOnS1.Y()==v1)
       &&(MyParOnS2.X()==u2)&&(MyParOnS2.Y()==v2)) {
      return(MyIsTangent);
    }
    else if(MyHasBeenComputedbis == Standard_False) { 
      MyTgbis         = MyTg;
      MyTguv1bis      = MyTguv1;
      MyTguv2bis      = MyTguv2;
      MyPntbis        = MyPnt;
      MyParOnS1bis    = MyParOnS1;
      MyParOnS2bis    = MyParOnS2;
      MyIsTangentbis  = MyIsTangent;
      MyHasBeenComputedbis = MyHasBeenComputed; 
    }
  }
  if(MyHasBeenComputedbis) { 
    if(  (MyParOnS1bis.X()==u1)&&(MyParOnS1bis.Y()==v1)
       &&(MyParOnS2bis.X()==u2)&&(MyParOnS2bis.Y()==v2)) {

      gp_Vec            TV(MyTg);
      gp_Vec2d          TV1(MyTguv1);
      gp_Vec2d          TV2(MyTguv2);
      gp_Pnt            TP(MyPnt);
      gp_Pnt2d          TP1(MyParOnS1);
      gp_Pnt2d          TP2(MyParOnS2);
      Standard_Boolean  TB=MyIsTangent;

      MyTg        = MyTgbis;
      MyTguv1     = MyTguv1bis;
      MyTguv2     = MyTguv2bis;
      MyPnt       = MyPntbis;
      MyParOnS1   = MyParOnS1bis;
      MyParOnS2   = MyParOnS2bis;
      MyIsTangent = MyIsTangentbis;

      MyTgbis         = TV;
      MyTguv1bis      = TV1;
      MyTguv2bis      = TV2;
      MyPntbis        = TP;
      MyParOnS1bis    = TP1;
      MyParOnS2bis    = TP2;
      MyIsTangentbis  = TB;

      return(MyIsTangent);
    }
  }


  MyIsTangent = Standard_True;

  static TColStd_Array1OfReal Param(1,4);
  Param(1) = u1; Param(2) = v1;
  Param(3) = u2; Param(4) = v2;
  math_FunctionSetRoot  Rsnld(MyIntersectionOn2S.Function());
  MyIntersectionOn2S.Perform(Param,Rsnld);
  if (!MyIntersectionOn2S.IsDone())  { 
    MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
    return(Standard_False);
  }
  if (MyIntersectionOn2S.IsEmpty()) {
    MyIsTangent=Standard_False;
    //cout<<"\n----- Parametree Parametree : IsEmpty ds Compute "<<endl;
    //Debug(u1); Debug(u2); Debug(v1); Debug(v2);   cout<<endl;
    MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
    return(Standard_False);
  }
  MyHasBeenComputed = Standard_True;
  MyPnt = P = MyIntersectionOn2S.Point().Value();
  
  MyIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
  MyParOnS1.SetCoord(tu1,tv1);
  MyParOnS2.SetCoord(tu2,tv2);
  
  if(MyIntersectionOn2S.IsTangent()) { 
    MyIsTangent=Standard_False;
    MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
    return(Standard_False); 
  }
  MyTg    = Tg    = MyIntersectionOn2S.Direction();
  MyTguv1 = Tguv1 = MyIntersectionOn2S.DirectionOnS1();
  MyTguv2 = Tguv2 = MyIntersectionOn2S.DirectionOnS2();

  //----------------------------------------------------------------------
  //-- Si ( Tg )    TU et TV sont normes 
  //-- 
  //-- On a    Tg   =  DeltaU  *  TU    +   DeltaV  *  TV
  //-- 
  //-- soit :  Tg.TU  =  DeltaU  TU.TU  +   DeltaV  TU.TV
  //--         Tg.TV  =  DeltaU  TV.TU  +   DeltaV  TV.TV 
  //-- 
  //-- Donc : 
  //--
  //--               Tg.TU TV.TV  - Tg.TV * TU.TV
  //--   DeltaU = -------------------------------
  //--               TU.TU TV.TV  - (TU.TV)**2
  //-- 
  //--               Tg.TV TU.TU  - Tg.TU * TU.TV
  //--   DeltaV = -------------------------------
  //--               TU.TU TV.TV  - (TU.TV)**2
  //--
  //--

  Tg.Normalize();    MyTg = Tg; 

  Standard_Real DeltaU,DeltaV;
  gp_Vec TU,TV;
  gp_Pnt Pbid;
  Standard_Real TUTV,TgTU,TgTV,TUTU,TVTV,DIS;
  //------------------------------------------------------------
  //-- Calcul de Tguv1
  //--
  ThePSurfaceTool::D1(MySurf1,u1,v1,Pbid,TU,TV);
  
  TUTU = TU.Dot(TU);
  TVTV = TV.Dot(TV);
  TUTV = TU.Dot(TV);
  TgTU = Tg.Dot(TU);
  TgTV = Tg.Dot(TV);
  DIS  = TUTU * TVTV - TUTV * TUTV;
  
  DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ; 
  DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;

  Tguv1.SetCoord(DeltaU,DeltaV);  MyTguv1 = Tguv1;

  //------------------------------------------------------------
  //-- Calcul de Tguv2
  //--  
  ThePSurfaceTool::D1(MySurf2,u2,v2,Pbid,TU,TV);

  TUTU = TU.Dot(TU);
  TVTV = TV.Dot(TV);
  TUTV = TU.Dot(TV);
  TgTU = Tg.Dot(TU);
  TgTV = Tg.Dot(TV);
  DIS  = TUTU * TVTV - TUTV * TUTV;

  DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ; 
  DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
  
  Tguv2.SetCoord(DeltaU,DeltaV);  MyTguv2 = Tguv2;

  return(Standard_True);
}
//--------------------------------------------------------------------------------
void ApproxInt_PrmPrmSvSurfaces::Pnt(const Standard_Real u1,
				     const Standard_Real v1,
				     const Standard_Real u2,
				     const Standard_Real v2,
				     gp_Pnt& P) { 
  gp_Pnt aP;
  gp_Vec aT;
  gp_Vec2d aTS1,aTS2;
  Standard_Real tu1=u1;
  Standard_Real tu2=u2;
  Standard_Real tv1=v1;
  Standard_Real tv2=v2;
  this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
  P=MyPnt;
}
//--------------------------------------------------------------------------------
Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Tangency(const Standard_Real u1,
						      const Standard_Real v1,
						      const Standard_Real u2,
						      const Standard_Real v2,
						      gp_Vec& T) { 
  gp_Pnt aP;
  gp_Vec aT;
  gp_Vec2d aTS1,aTS2;
  Standard_Real tu1=u1;
  Standard_Real tu2=u2;
  Standard_Real tv1=v1;
  Standard_Real tv2=v2;
  Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
  T=MyTg;
  return(t);
}
//--------------------------------------------------------------------------------
Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf1(const Standard_Real u1,
							     const Standard_Real v1,
							     const Standard_Real u2,
							     const Standard_Real v2,
							     gp_Vec2d& T) { 
  gp_Pnt aP;
  gp_Vec aT;
  gp_Vec2d aTS1,aTS2;
  Standard_Real tu1=u1;
  Standard_Real tu2=u2;
  Standard_Real tv1=v1;
  Standard_Real tv2=v2;
  Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
  T=MyTguv1;
  return(t);
}
//--------------------------------------------------------------------------------
Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf2(const Standard_Real u1,
							     const Standard_Real v1,
							     const Standard_Real u2,
							     const Standard_Real v2,
							     gp_Vec2d& T) { 
  gp_Pnt aP;
  gp_Vec aT;
  gp_Vec2d aTS1,aTS2;
  Standard_Real tu1=u1;
  Standard_Real tu2=u2;
  Standard_Real tv1=v1;
  Standard_Real tv2=v2;
  Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
  T=MyTguv2;
  return(t);
}
//--------------------------------------------------------------------------------




#if 0 
  //------------------------------------------------------------
  //-- Calcul de Tguv1
  //--
  ThePSurfaceTool::D1(MySurf1,u1,v1,P,TU,TV);
  
  TUTV = TU.Dot(TV);
  TgTU = Tg.Dot(TU);
  TgTV = Tg.Dot(TV);
  UmTUTV2 = 1.0 - TUTV * TUTV;
  
  DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ; 
  DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;

  Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
  
  Tguv1.Multiplied(Delta);  MyTguv1 = Tguv1;

  //------------------------------------------------------------
  //-- Calcul de Tguv2
  //--  
  ThePSurfaceTool::D1(MySurf2,u2,v2,P,TU,TV);

  TUTV = TU.Dot(TV);
  TgTU = Tg.Dot(TU);
  TgTV = Tg.Dot(TV);
  UmTUTV2 = 1.0 - TUTV * TUTV;
  
  DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ; 
  DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
  
  Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
  
  Tguv2.Multiplied(Delta);  MyTguv2 = Tguv2;

  return(Standard_True);
}
#endif