Plot a smiley face function in C#

example

This example shows how you can plot a smiley face function defined by the following equations.

[x^2 + y^2 - 225] *
[x^2 + y^2 - 10000] *
[(x - 45)^2 + (y - 35)^2 - 225] *
[(x + 45)^2 + (y - 35)^2 - 225] = 0

[y + Sqrt(16 - x^2)] = 0

You can use the techniques described in the following examples to plot the equations.

This example uses the PlotFunction method from the first of the previous examples in the following calls:

PlotFunction(gr, F1, -6, -6, 6, 6, dx, dy);
PlotFunction(gr, F2, -6, -6, 6, 6, dx, dy);

The following code shows the F1 and F2 functions.

// Calculate:
//   [x^2 + y^2 - 225] *
//   [x^2 + y^2 - 10000] *
//   [(x - 45)^2 + (y - 35)^2 - 225] *
//   [(x + 45)^2 + (y - 35)^2 - 225]
private float F1(float x, float y)
{
    // Flip y to make the image appear right side up.
    return
        (x * x + y * y - 25f) *
        (x * x + y * y - 1f) *
        ((x - 2.5f) * (x - 2.5f) + (y - 2.0f) * (y - 2.0f) - 1f) *
        ((x + 2.5f) * (x + 2.5f) + (y - 2.0f) * (y - 2.0f) - 1f);
}

// Calculate:
//   y + Sqrt(16 - x^2)
private float F2(float x, float y)
{
    return (float)(y + Math.Sqrt(12.25f - x * x));
}


Download Example   Follow me on Twitter   RSS feed




This entry was posted in algorithms, graphics, mathematics and tagged , , , , , , , , , , , . Bookmark the permalink.

One Response to Plot a smiley face function in C#

  1. Pingback: Plot a heart-shaped function in C# -

Leave a Reply

Your email address will not be published. Required fields are marked *