, Visual C#


         

ref float x, ref float


private void FindPointOnCurve( ref float x, ref float y,
float LevelCurves, float start_x, float start_y,
float tolerance)
{
float dx = 0, dy = 0, dz, delta, f_xy;
int direction = 0;
// :
x = start_x; y = start_y; delta = initial_delta;
// do-while break:
int i = 0;
do
{
f_xy = f(x, y); dz = LevelCurves - f_xy;
if (Math.Abs(dz) < tolerance) break;
// :
if (Math.Sign(dz) != direction)
{
// . delta:
delta = delta / 2;
direction = Math.Sign(dz);
}
// :
Gradient(x, y, ref dx, ref dy);
if ((Math.Abs(dx) + Math.Abs(dy)) < 0.001) break;
// :
x = x + dx * delta * (float)direction;
y = y + dy * delta * (float)direction;
}
while (i < 1);
}
// :
private void Gradient(float x, float y,
ref float dx, ref float dy)
{
float dist = 0;
dx = df_dx(x, y); dy = df_dy(x, y);
dist = Convert.ToSingle(Math.Sqrt(dx * dx + dy * dy));
if (Math.Abs(dist) < 0.0001)
{
dx = 0; dy = 0;
}
else
{
dx = dx / dist; dy = dy / dist;
}
}
// f(x, y) = LevelCurves:
private void PlotLevelCurve(Graphics g,
float LevelCurves, float x_min, float x_max, float y_min,
float y_max, float step_size,
float start_x, float start_y,
float tolerance)
{
int num_points = 0;
float x0 = 0, y0 = 0, x1, y1, x2, y2, dx = 0, dy = 0;
// (x0, y0) LevelCurves:
FindPointOnCurve(ref x0, ref y0, LevelCurves,
start_x, start_y, tolerance);
//:
num_points = 1;