summaryrefslogtreecommitdiff
path: root/src/BRepBlend/BRepBlend_SurfPointEvolRadInv.cxx
blob: c1c8f1a29b8b1df6b9596c7f6e820be6ca83577e (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
// File:	BRepBlend_SurfPointEvolRadInv.cxx
// Created:	Tue Jul 29 12:13:05 1997
// Author:	Jerome LEMONIER
//		<jlr@sgi64>


#include <BRepBlend_SurfPointEvolRadInv.ixx>


//=======================================================================
//function : 
//purpose  : 
//=======================================================================
BRepBlend_SurfPointEvolRadInv::BRepBlend_SurfPointEvolRadInv
(const Handle(Adaptor3d_HSurface)& S,
const Handle(Adaptor3d_HCurve)& C,
 const Handle(Law_Function)& Evol
) : surf(S), curv(C)
{ tevol=Evol;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 void BRepBlend_SurfPointEvolRadInv::Set(const Standard_Integer Choix) 
{  choix = Choix;
  switch (choix) {
  case 1 :
  case 2 :
    sg1 = -1;
    break;
  case 3 :
  case 4 :
    sg1 = 1;
    break;
  default :
    sg1 = -1;
    break;
  }
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 Standard_Integer BRepBlend_SurfPointEvolRadInv::NbEquations() const
{
  return 3;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 Standard_Boolean BRepBlend_SurfPointEvolRadInv::Value(const math_Vector& X,math_Vector& F) 
{
  Standard_Real theD,norm,unsurnorm;
  gp_Pnt ptcur,pts;
  gp_Vec d1cur,d1u,d1v;
  gp_XYZ nplan(0.,0.,0.),ns(0.,0.,0.),ref(0.,0.,0.);
  curv->D1(X(1),ptcur,d1cur);
  ray = sg1*tevol->Value(X(1));
  nplan = d1cur.Normalized().XYZ();
  theD = -(nplan.Dot(ptcur.XYZ()));
  surf->D1(X(2),X(3),pts,d1u,d1v);
  F(1) = nplan.Dot(point.XYZ()) + theD;
  F(2) = nplan.Dot(pts.XYZ()) + theD;
  ns = d1u.Crossed(d1v).XYZ();
  norm = nplan.Crossed(ns).Modulus();
  unsurnorm = 1./norm;
  ns.SetLinearForm(nplan.Dot(ns),nplan, -1.,ns);
  ns.Multiply(unsurnorm);
  ref = pts.XYZ() - point.XYZ();
  ref.SetLinearForm(ray,ns,ref);
  F(3) = ref.SquareModulus() - ray*ray;
  return Standard_True;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 Standard_Boolean BRepBlend_SurfPointEvolRadInv::Derivatives(const math_Vector& X,math_Matrix& D) 
{
  gp_Pnt ptcur,pts;
  gp_Vec d1cur,d2cur,nplan,dnplan,d1u,d1v,d2u,d2v,duv;
  Standard_Real dtheD, normd1cur, unsurnormd1cur,dray;

  curv->D2(X(1),ptcur,d1cur,d2cur);
  tevol->D1(X(1),ray,dray);
  ray=sg1*ray;
  dray=sg1*dray;
  normd1cur = d1cur.Magnitude();
  unsurnormd1cur = 1./normd1cur;
  nplan = unsurnormd1cur * d1cur;
  dnplan.SetLinearForm(-nplan.Dot(d2cur),nplan,d2cur);
  dnplan.Multiply(unsurnormd1cur);
  dtheD = - nplan.XYZ().Dot(d1cur.XYZ()) - dnplan.XYZ().Dot(ptcur.XYZ());
  D(1,1) = dnplan.XYZ().Dot(point.XYZ()) + dtheD;
  D(1,2) = D(1,3) = 0.;
  surf->D2(X(2),X(3),pts,d1u,d1v,d2u,d2v,duv);
  D(2,1) = dnplan.XYZ().Dot(pts.XYZ()) + dtheD;
  D(2,2) = nplan.Dot(d1u);
  D(2,3) = nplan.Dot(d1v);
  
  gp_Vec nsurf = d1u.Crossed(d1v);
  gp_Vec dunsurf = d2u.Crossed(d1v).Added(d1u.Crossed(duv));
  gp_Vec dvnsurf = d1u.Crossed(d2v).Added(duv.Crossed(d1v));

  gp_Vec nplancrosnsurf = nplan.Crossed(nsurf);
  gp_Vec dwnplancrosnsurf = dnplan.Crossed(nsurf);
  gp_Vec dunplancrosnsurf = nplan.Crossed(dunsurf);
  gp_Vec dvnplancrosnsurf = nplan.Crossed(dvnsurf);

  Standard_Real norm2      = nplancrosnsurf.SquareMagnitude();
  Standard_Real norm       = sqrt(norm2);
  Standard_Real unsurnorm  = 1./norm;
  Standard_Real raysurnorm = ray*unsurnorm;
  Standard_Real unsurnorm2 = unsurnorm * unsurnorm;
  Standard_Real raysurnorm2 = ray*unsurnorm2;
  Standard_Real dwnorm = unsurnorm*nplancrosnsurf.Dot(dwnplancrosnsurf);
  Standard_Real dunorm = unsurnorm*nplancrosnsurf.Dot(dunplancrosnsurf);
  Standard_Real dvnorm = unsurnorm*nplancrosnsurf.Dot(dvnplancrosnsurf);

  Standard_Real nplandotnsurf   = nplan.Dot(nsurf);
  Standard_Real dwnplandotnsurf = dnplan.Dot(nsurf);
  Standard_Real dunplandotnsurf = nplan.Dot(dunsurf);
  Standard_Real dvnplandotnsurf = nplan.Dot(dvnsurf);
  
  gp_Vec temp,dwtemp,dutemp,dvtemp;
  temp.SetLinearForm(nplandotnsurf,nplan,-1.,nsurf);
  dwtemp.SetLinearForm(nplandotnsurf,dnplan,dwnplandotnsurf,nplan);
  dutemp.SetLinearForm(dunplandotnsurf,nplan,-1.,dunsurf);
  dvtemp.SetLinearForm(dvnplandotnsurf,nplan,-1.,dvnsurf);

  gp_Vec ref,dwref,duref,dvref,corde(point,pts);
  ref.SetLinearForm(raysurnorm,temp,corde);
  dwref.SetLinearForm(raysurnorm,dwtemp,-raysurnorm2*dwnorm,temp);
  dwref.SetLinearForm(1.,dwref,dray*unsurnorm,temp);
  duref.SetLinearForm(raysurnorm,dutemp,-raysurnorm2*dunorm,temp,d1u);
  dvref.SetLinearForm(raysurnorm,dvtemp,-raysurnorm2*dvnorm,temp,d1v);
  
  ref.Add(ref);
  D(3,1) = ref.Dot(dwref) - 2.*dray*ray;
  D(3,2) = ref.Dot(duref);
  D(3,3) = ref.Dot(dvref);

  return Standard_True;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 Standard_Boolean BRepBlend_SurfPointEvolRadInv::Values(const math_Vector& X,math_Vector& F,math_Matrix& D) 
{
  gp_Pnt ptcur,pts;
  gp_Vec d1cur,d2cur,nplan,dnplan,d1u,d1v,d2u,d2v,duv;
  Standard_Real theD, dtheD, normd1cur, unsurnormd1cur,dray;

  curv->D2(X(1),ptcur,d1cur,d2cur);
  tevol->D1(X(1),ray,dray);
  ray=sg1*ray;
  dray=sg1*dray;
  surf->D2(X(2),X(3),pts,d1u,d1v,d2u,d2v,duv);
  normd1cur = d1cur.Magnitude();
  unsurnormd1cur = 1./normd1cur;
  nplan = unsurnormd1cur * d1cur;
  theD = -(nplan.XYZ().Dot(ptcur.XYZ()));
  F(1) = nplan.XYZ().Dot(point.XYZ()) + theD;
  F(2) = nplan.XYZ().Dot(pts.XYZ()) + theD;

  dnplan.SetLinearForm(-nplan.Dot(d2cur),nplan,d2cur);
  dnplan.Multiply(unsurnormd1cur);
  dtheD = - nplan.XYZ().Dot(d1cur.XYZ()) - dnplan.XYZ().Dot(ptcur.XYZ());
  D(1,1) = dnplan.XYZ().Dot(point.XYZ()) + dtheD;
  D(1,2) = D(1,3) = 0.;
  D(2,1) = dnplan.XYZ().Dot(pts.XYZ()) + dtheD;
  D(2,2) = nplan.Dot(d1u);
  D(2,3) = nplan.Dot(d1v);
  
  gp_Vec nsurf = d1u.Crossed(d1v);
  gp_Vec dunsurf = d2u.Crossed(d1v).Added(d1u.Crossed(duv));
  gp_Vec dvnsurf = d1u.Crossed(d2v).Added(duv.Crossed(d1v));

  gp_Vec nplancrosnsurf = nplan.Crossed(nsurf);
  gp_Vec dwnplancrosnsurf = dnplan.Crossed(nsurf);
  gp_Vec dunplancrosnsurf = nplan.Crossed(dunsurf);
  gp_Vec dvnplancrosnsurf = nplan.Crossed(dvnsurf);

  Standard_Real norm2      = nplancrosnsurf.SquareMagnitude();
  Standard_Real norm       = sqrt(norm2);
  Standard_Real unsurnorm  = 1./norm;
  Standard_Real raysurnorm = ray*unsurnorm;
  Standard_Real unsurnorm2 = unsurnorm * unsurnorm;
  Standard_Real raysurnorm2 = ray*unsurnorm2;
  Standard_Real dwnorm = unsurnorm*nplancrosnsurf.Dot(dwnplancrosnsurf);
  Standard_Real dunorm = unsurnorm*nplancrosnsurf.Dot(dunplancrosnsurf);
  Standard_Real dvnorm = unsurnorm*nplancrosnsurf.Dot(dvnplancrosnsurf);

  Standard_Real nplandotnsurf   = nplan.Dot(nsurf);
  Standard_Real dwnplandotnsurf = dnplan.Dot(nsurf);
  Standard_Real dunplandotnsurf = nplan.Dot(dunsurf);
  Standard_Real dvnplandotnsurf = nplan.Dot(dvnsurf);
  
  gp_Vec temp,dwtemp,dutemp,dvtemp;
  temp.SetLinearForm(nplandotnsurf,nplan,-1.,nsurf);
  dwtemp.SetLinearForm(nplandotnsurf,dnplan,dwnplandotnsurf,nplan);
  dutemp.SetLinearForm(dunplandotnsurf,nplan,-1.,dunsurf);
  dvtemp.SetLinearForm(dvnplandotnsurf,nplan,-1.,dvnsurf);

  gp_Vec ref,dwref,duref,dvref,corde(point,pts);
  ref.SetLinearForm(raysurnorm,temp,corde);
  F(3) = ref.SquareMagnitude() - ray*ray;
  dwref.SetLinearForm(raysurnorm,dwtemp,-raysurnorm2*dwnorm,temp);
  dwref.SetLinearForm(1.,dwref,dray*unsurnorm,temp);
  duref.SetLinearForm(raysurnorm,dutemp,-raysurnorm2*dunorm,temp,d1u);
  dvref.SetLinearForm(raysurnorm,dvtemp,-raysurnorm2*dvnorm,temp,d1v);
  
  ref.Add(ref);
  D(3,1) = ref.Dot(dwref) - 2.*dray*ray;
  D(3,2) = ref.Dot(duref);
  D(3,3) = ref.Dot(dvref);

  return Standard_True;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 void BRepBlend_SurfPointEvolRadInv::Set(const gp_Pnt& P) 
{
  point = P;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 void BRepBlend_SurfPointEvolRadInv::GetTolerance(math_Vector& Tolerance,const Standard_Real Tol) const
{
  Tolerance(1) = curv->Resolution(Tol);
  Tolerance(2) = surf->UResolution(Tol);
  Tolerance(3) = surf->VResolution(Tol);
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 void BRepBlend_SurfPointEvolRadInv::GetBounds(math_Vector& InfBound,math_Vector& SupBound) const
{
  InfBound(1) = curv->FirstParameter();
  SupBound(1) = curv->LastParameter();
  InfBound(2) = surf->FirstUParameter();
  SupBound(2) = surf->LastUParameter();
  InfBound(3) = surf->FirstVParameter();
  SupBound(3) = surf->LastVParameter();
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
 Standard_Boolean BRepBlend_SurfPointEvolRadInv::IsSolution(const math_Vector& Sol,const Standard_Real Tol) 
{
  math_Vector valsol(1,3);
  Value(Sol,valsol);
  if (Abs(valsol(1)) <= Tol && 
      Abs(valsol(2)) <= Tol &&
      Abs(valsol(3)) <= 2*Tol*Abs(ray) ) {
    return Standard_True;
  }
  return Standard_False;
}