Plot functions in C#

[Plot functions]

This example shows how to plot functions. This example plots a function that represents a heart shape.

The earlier example Plot a heart-shaped function in C# shows how to draw a relatively complex heart-shaped function. Recently I saw a much simpler function on a t-shirt at (Although it doesn’t seem to be available any more.)

The equation is:

This example is the same as the previous one except it plots the following function.

// The function.
private float HeartFunc(float x, float y)
    double a = x * x;
    double b = y - Math.Pow(x * x, (double)1 / 3);
    return (float)(a + b * b - 1);

The basic idea is to convert the original function into one with value equal to 0, in this example by subtracting 1 from both sides of the equals sign. The program then examines the pixels in the image. If the value of the function crosses 0 between two pixels, then the spot between them should be part of the plot.

See the previous example for more details.

Download Example   Follow me on Twitter   RSS feed   Donate

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

1 Response to Plot functions in C#

  1. This is a great idea. You did an amazing job! Thanks so much for sharing.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.