summaryrefslogtreecommitdiff
path: root/src/Extrema/Extrema_FuncExtSS.cxx
blob: 89e9a86d3dfd5073c2c26319ab61ebf73f72bdbc (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
// File:	Extrema_FuncExtSS.cxx
// Created:	Tue Jan  9 10:13:04 1996
// Author:	Laurent PAINNOT
//		<lpa@nonox>


#include <Extrema_FuncExtSS.ixx>
#include <Standard_TypeMismatch.hxx>
#include <gp_Vec.hxx>


/*----------------------------------------------------------------------------
 Si on note Du1s et Dv1s, les derivees en u1 et v1, les 2 fonctions a annuler sont:
 Si on note Du2s et Dv2s, les derivees en u2 et v2, les 2 fonctions a annuler sont:

 { F1(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Du1s1(u1,v1) }
 { F2(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Dv1s1(u1,v1) }
 { F3(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Du2s2(u2,v2) }
 { F4(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Dv2s2(u2,v2) }

 { du1f1(u1,v1,u2,v2) = Du1s1(u1,v1).Du1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1u1s1(u1,v1) 
                      = ||Du1s1(u1,v1)||**2      +(S1(u1,v1)-S2(u2,v2)).Du1u1s1(u1,v1) }
 { dv1f1(u1,v1,u2,v2) = Dv1s1(u1,v1).Du1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1v1s1(u1,v1) }
 { du2f1(u1,v1,u2,v2) = -Du2s2(u2,v2).Du1s1(u1,v1) }
 { dv2f1(u1,v1,u2,v2) = -Dv2s2(u2,v2).Du1s1(u1,v1) }

 { du1f2(u1,v1,u2,v2) = Du1s1(u1,v1).Dv1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1v1s1(u1,v1) }
 { dv1f2(u1,v1,u2,v2) = Dv1s1(u1,v1).Dv1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Dv1v1s1(u1,v1) 
                      = ||Dv1s1(u1,v1)||**2      +(S1(u1,v1)-S2(u2,v2)).Dv1v1s1(u1,v1) }
 { du2f2(u1,v1,u2,v2) = -Du2s2(u2,v2).Dv1s1(u1,v1) }
 { dv2f2(u1,v1,u2,v2) = -Dv2s2(u2,v2).Dv1s1(u1,v1) }

 { du1f3(u1,v1,u2,v2) = Du1s1(u1,v1).Du2s2(u2,v2) }
 { dv1f3(u1,v1,u2,v2) = Dv1s1(u1,v1).Du2s2(u2,v2) }
 { du2f3(u1,v1,u2,v2) = -Du2s2(u2,v2).Du2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Du2u2s2(u2,v2) 
                      = -||Du2s2(u2,v2)||**2      +(S1(u1,v1)-S2(u2,v2)).Du2u2s2(u2,v2) }
 { dv2f3(u1,v1,u2,v2) = -Dv2s2(u2,v2).Du2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Dv2u2s2(u2,v2) }

 { du1f4(u1,v1,u2,v2) = Du1s1(u1,v1).Dv2s2(u2,v2) }
 { dv1f4(u1,v1,u2,v2) = Dv1s1(u1,v1).Dv2s2(u2,v2) }
 { du2f4(u1,v1,u2,v2) = -Du2s2(u2,v2).Dv2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Du2v2s2(u2,v2) }
 { dv2f4(u1,v1,u2,v2) = -Dv2s2(u2,v2).Dv2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) 
                      = -||Dv2s2(u2,v2)||**2      +(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) }

----------------------------------------------------------------------------*/


//=======================================================================
//function : Extrema_FuncExtSS
//purpose  : 
//=======================================================================

Extrema_FuncExtSS::Extrema_FuncExtSS ()
{
  myS1init = Standard_False;
  myS2init = Standard_False;
}

//=======================================================================
//function : Extrema_FuncExtSS
//purpose  : 
//=======================================================================

Extrema_FuncExtSS::Extrema_FuncExtSS (const Adaptor3d_Surface& S1,
				      const Adaptor3d_Surface& S2)
{
  myS1 = (Adaptor3d_SurfacePtr)&S1;
  myS2 = (Adaptor3d_SurfacePtr)&S2;
  myS1init = Standard_True;
  myS2init = Standard_True;
}

//=======================================================================
//function : Initialize
//purpose  : 
//=======================================================================

void Extrema_FuncExtSS::Initialize(const Adaptor3d_Surface& S1,
				   const Adaptor3d_Surface& S2)
{
  myS1 = (Adaptor3d_SurfacePtr)&S1;
  myS2 = (Adaptor3d_SurfacePtr)&S2;
  myS1init = Standard_True;
  myS2init = Standard_True;
  myPoint1.Clear();
  myPoint2.Clear();
  mySqDist.Clear();
}



//=======================================================================
//function : NbVariables
//purpose  : 
//=======================================================================

Standard_Integer Extrema_FuncExtSS::NbVariables () const { return 4;}


//=======================================================================
//function : NbEquations
//purpose  : 
//=======================================================================

Standard_Integer Extrema_FuncExtSS::NbEquations () const { return 4;}


//=======================================================================
//function : Value
//purpose  : 
//=======================================================================

Standard_Boolean Extrema_FuncExtSS::Value (const math_Vector& UV, 
					   math_Vector& F)
{
  if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
  myU1 = UV(1);
  myV1 = UV(2);
  myU2 = UV(3);
  myV2 = UV(4);
  gp_Vec Du1s1, Dv1s1;
  gp_Vec Du2s2, Dv2s2;
  myS1->D1(myU1,myV1,myP1,Du1s1,Dv1s1);
  myS2->D1(myU2,myV2,myP2,Du2s2,Dv2s2);

  gp_Vec P1P2 (myP2,myP1);

  F(1) = P1P2.Dot(Du1s1);
  F(2) = P1P2.Dot(Dv1s1);
  F(3) = P1P2.Dot(Du2s2);
  F(4) = P1P2.Dot(Dv2s2);

  return Standard_True;  
}

//=======================================================================
//function : Derivatives
//purpose  : 
//=======================================================================

Standard_Boolean Extrema_FuncExtSS::Derivatives (const math_Vector& UV, 
						 math_Matrix& Df)
{
  math_Vector F(1,4);
  return Values(UV,F,Df);
}

//=======================================================================
//function : Values
//purpose  : 
//=======================================================================

Standard_Boolean Extrema_FuncExtSS::Values (const math_Vector& UV, 
					    math_Vector& F,
					    math_Matrix& Df)
{
  if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
  myU1 = UV(1);
  myV1 = UV(2);
  myU2 = UV(3);
  myV2 = UV(4);
  gp_Vec Du1s1, Dv1s1, Du1u1s1, Dv1v1s1, Du1v1s1;
  gp_Vec Du2s2, Dv2s2, Du2u2s2, Dv2v2s2, Du2v2s2;
  myS1->D2(myU1,myV1,myP1,Du1s1,Dv1s1,Du1u1s1,Dv1v1s1,Du1v1s1);
  myS2->D2(myU2,myV2,myP2,Du2s2,Dv2s2,Du2u2s2,Dv2v2s2,Du2v2s2);

  gp_Vec P1P2 (myP2,myP1);

  F(1) = P1P2.Dot(Du1s1);
  F(2) = P1P2.Dot(Dv1s1);
  F(3) = P1P2.Dot(Du2s2);
  F(4) = P1P2.Dot(Dv2s2);

  Df(1,1) = Du1s1.SquareMagnitude() + P1P2.Dot(Du1u1s1);
  Df(1,2) = Dv1s1.Dot(Du1s1) + P1P2.Dot(Du1v1s1);
  Df(1,3) = -Du2s2.Dot(Du1s1);
  Df(1,4) = -Dv2s2.Dot(Du1s1);

  Df(2,1) = Df(1, 2);   // Du1s1.Dot(Dv1s1) + P1P2.Dot(Du1v1s1);
  Df(2,2) = Dv1s1.SquareMagnitude() + P1P2.Dot(Dv1v1s1);
  Df(2,3) = -Du2s2.Dot(Dv1s1);
  Df(2,4) = -Dv2s2.Dot(Dv1s1);

  Df(3,1) = -Df(1,3);   // Du1s1.Dot(Du2s2);
  Df(3,2) = -Df(2,3);   // Dv1s1.Dot(Du2s2);
  Df(3,3) = -Du2s2.SquareMagnitude() + P1P2.Dot(Du2u2s2);
  Df(3,4) = -Dv2s2.Dot(Du2s2) + P1P2.Dot(Du2v2s2);

  Df(4,1) = -Df(1,4);   // Du1s1.Dot(Dv2s2);
  Df(4,2) = -Df(2,4);   // Dv1s1.Dot(Dv2s2);
  Df(4,3) = Df(3,4);    // -Du2s2.Dot(Dv2s2) + P1P2.Dot(Du2v2s2);
  Df(4,4) = -Dv2s2.SquareMagnitude() + P1P2.Dot(Dv2v2s2);

  return Standard_True;
}

//=======================================================================
//function : GetStateNumber
//purpose  : 
//=======================================================================

Standard_Integer Extrema_FuncExtSS::GetStateNumber ()
{
  if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
#if 0
  math_Vector Sol(1, 4), UVSol(1, 4);
  UVSol(1) = myU1; UVSol(2) = myV1; UVSol(3) = myU2; UVSol(4) = myV2;
  Value(UVSol, Sol);
  cout <<"F(1)= "<<Sol(1)<<" F(2)= "<<Sol(2)<<" F(3)= "<<Sol(3)<<" F(4)= "<<Sol(4)<<endl;
#endif

  mySqDist.Append(myP1.SquareDistance(myP2));
  myPoint1.Append(Extrema_POnSurf(myU1,myV1,myP1));
  myPoint2.Append(Extrema_POnSurf(myU2,myV2,myP2));
  return 0;
}

//=======================================================================
//function : NbExt
//purpose  : 
//=======================================================================

Standard_Integer Extrema_FuncExtSS::NbExt () const
{
  return mySqDist.Length();
}

//=======================================================================
//function : SquareDistance
//purpose  : 
//=======================================================================

Standard_Real Extrema_FuncExtSS::SquareDistance (const Standard_Integer N) const
{
  if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
  return mySqDist.Value(N);
}

//=======================================================================
//function : PointOnS1
//purpose  : 
//=======================================================================

Extrema_POnSurf Extrema_FuncExtSS::PointOnS1 (const Standard_Integer N) const
{
  if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
  return myPoint1.Value(N);
}
//=======================================================================
//function : PointOnS2
//purpose  : 
//=======================================================================

Extrema_POnSurf Extrema_FuncExtSS::PointOnS2 (const Standard_Integer N) const
{
  if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
  return myPoint2.Value(N);
}