summaryrefslogtreecommitdiff
path: root/src/BlendFunc/BlendFunc_Corde.cxx
blob: 2321c44f7bdd9e514b8d6b51dc02f7dbce837cb0 (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
// File:      BlendFunc_Corde.cxx
// Created:   Tue Jun  4 18:12:59 1996
// Author:    Stagiaire Xuan Trang PHAMPHU
// Copyright: OPEN CASCADE 1996

#include <BlendFunc_Corde.ixx>

#include <math_Gauss.hxx>

#include <ElCLib.hxx>
#include <gp.hxx>
#include <BlendFunc.hxx>
#include <Standard_DomainError.hxx>
#include <Standard_NotImplemented.hxx>


//=======================================================================
//function : BlendFunc_Corde
//purpose  : 
//=======================================================================

BlendFunc_Corde::BlendFunc_Corde(const Handle(Adaptor3d_HSurface)&   S,
                                 const Handle(Adaptor3d_HCurve)&     CG) :
    surf(S),guide(CG)
{
}

//=======================================================================
//function : SetDist
//purpose  : 
//=======================================================================

void BlendFunc_Corde::SetDist(const Standard_Real Dist)
{
  dis = Dist;
}

//=======================================================================
//function : SetParam
//purpose  : 
//=======================================================================

void BlendFunc_Corde::SetParam(const Standard_Real Param)
{
  guide->D2(Param,ptgui,d1gui,d2gui);
  normtg = d1gui.Magnitude();
  nplan  = d1gui.Normalized();
  theD = - (nplan.XYZ().Dot(ptgui.XYZ()));
}

//=======================================================================
//function : Value
//purpose  : returns F(U,V)
//=======================================================================

Standard_Boolean BlendFunc_Corde::Value(const math_Vector& X, math_Vector& F)
{
  gp_Vec d1u,d1v;
  surf->D1(X(1),X(2),pts,d1u,d1v);

  F(1) = nplan.XYZ().Dot(pts.XYZ()) + theD;
  const gp_Vec vref(ptgui,pts);
  F(2) = vref.SquareMagnitude() - dis*dis; 

  return Standard_True;
}

//=======================================================================
//function : Derivatives
//purpose  : D = grad F(U,V)
//=======================================================================

Standard_Boolean BlendFunc_Corde::Derivatives(const math_Vector& X, math_Matrix& D)
{
  gp_Vec d1u,d1v;
  surf->D1(X(1),X(2),pts,d1u,d1v);  

  D(1,1) = nplan.Dot(d1u);
  D(1,2) = nplan.Dot(d1v); 
  D(2,1) = 2.*gp_Vec(ptgui,pts).Dot(d1u);
  D(2,2) = 2.*gp_Vec(ptgui,pts).Dot(d1v);

  return Standard_True;
}

//=======================================================================
//function : PointOnS
//purpose  : 
//=======================================================================

const gp_Pnt& BlendFunc_Corde::PointOnS () const
{
  return pts;
}


//=======================================================================
//function : PointOnGuide
//purpose  : 
//=======================================================================

const gp_Pnt& BlendFunc_Corde::PointOnGuide () const
{
  return ptgui;
}


//=======================================================================
//function : Nplan
//purpose  : 
//=======================================================================

const gp_Vec& BlendFunc_Corde::NPlan () const
{
  return nplan;
}


//=======================================================================
//function : IsTangencyPoint
//purpose  : 
//=======================================================================

Standard_Boolean BlendFunc_Corde::IsTangencyPoint () const
{
  return istangent;
}


//=======================================================================
//function : TangentOnS
//purpose  : 
//=======================================================================

const gp_Vec& BlendFunc_Corde::TangentOnS () const
{
  if (istangent)
    Standard_DomainError::Raise("BlendFunc_Corde::TangentOnS");
  return tgs;
}


//=======================================================================
//function : Tangent2dOnS
//purpose  : 
//=======================================================================

const gp_Vec2d& BlendFunc_Corde::Tangent2dOnS () const
{
  if (istangent) 
    Standard_DomainError::Raise("BlendFunc_Corde::Tangent2dOnS");
  return tg2d;
}


//=======================================================================
//function : DerFguide
//purpose  : dF/dw
//=======================================================================

void BlendFunc_Corde::DerFguide (const math_Vector& Sol, gp_Vec2d& DerF)
{
  gp_Vec d1u,d1v;
  surf->D1(Sol(1),Sol(2),pts,d1u,d1v);

  gp_Vec dnplan;
  dnplan.SetLinearForm(1./normtg,d2gui,-1./normtg*(nplan.Dot(d2gui)),nplan);

  const gp_Vec temp(pts.XYZ()-ptgui.XYZ());

  DerF.SetX( dnplan.Dot(temp)-nplan.Dot(d1gui) );
  DerF.SetY( -2.*d1gui.Dot(temp) );
}

//=======================================================================
//function : IsSolution
//purpose  :
//=======================================================================

Standard_Boolean BlendFunc_Corde::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
{
  math_Vector secmember(1,2),valsol(1,2);
  math_Matrix gradsol(1,2,1,2);

  gp_Vec dnplan,temp,d1u,d1v;

  Value(Sol,valsol);
  Derivatives(Sol,gradsol);
  if (Abs(valsol(1)) <= Tol &&
      Abs(valsol(2)) <= Tol*Tol) {

    surf->D1(Sol(1),Sol(2),pts,d1u,d1v);
    dnplan.SetLinearForm(1./normtg,d2gui,
			 -1./normtg*(nplan.Dot(d2gui)),nplan); 

    temp.SetXYZ(pts.XYZ()-ptgui.XYZ());

    secmember(1) = nplan.Dot(d1gui) - dnplan.Dot(temp);
    secmember(2) = 2.*d1gui.Dot(temp);

//  gradsol*der = secmember
//  with  der(1) = dU/dW, der(2) = dU/dW, W is the guide parameter

    math_Gauss Resol(gradsol);
    if (Resol.IsDone()) {
      Resol.Solve(secmember);
      tgs.SetLinearForm(secmember(1),d1u,secmember(2),d1v);
      tg2d.SetCoord(secmember(1),secmember(2));
      istangent = Standard_False;
    }
    else {
      istangent = Standard_True;
    }
    return Standard_True;
  }

  return Standard_False;
}