Plot a heart-shaped function in C#

This example is very similar to Plot a smiley face function in C#.

What does the graph of the following equation look like?

    [y - Sqrt(2.5 * 2.5 - (x - 2.5) * (x - 2.5))] *
[y - Sqrt(2.5 * 2.5 - (x + 2.5) * (x + 2.5))] *
[(-y - Sqrt(2.5 * 2.5 - (x - 2.5) * (x - 2.5)))
+ Sqrt(x - 2.5) - Sqrt(x - 2.5)] *
[(-y - Sqrt(2.5 * 2.5 - (-(x + 2.5)) *
(-(x + 2.5)))) + Sqrt(-(x + 2.5))
- Sqrt(-(x + 2.5))] *
[((y + 5) - Sqrt(2.5 * 2.5 - (x + 2.5) *
(x + 2.5))) + Sqrt(x + 2.5) - Sqrt(x + 2.5)] *
[((y + 5) - Sqrt(2.5 * 2.5 - ((x - 2.5))
* ((x - 2.5)))) + Sqrt(-(x - 2.5)) - Sqrt(-(x - 2.5))] = 0

Unless I messed up transcribing these (which is possible), they define the shape shown in here.

The only real trick to this kind of equation is to note that A * B = zero if A = 0 or B = 0 (or both). To graph this equation, you can graph each piece of it separately. That's important for this example because the technique used depends on noticing when a value changes from less than zero to greater than zero. Because the pieces of this equation are imaginary for many values of x and y, they are often neither less than or greater than 0 so that technique won't work.

The program uses the following code to graph each of the function's pieces.

PlotFunction(gr, F1, dx, dy);
PlotFunction(gr, F2, dx, dy);
PlotFunction(gr, F3, dx, dy);
PlotFunction(gr, F4, dx, dy);
PlotFunction(gr, F5, dx, dy);
PlotFunction(gr, F6, dx, dy);

The methods F1, F2, ..., F6 return the pieces of the whole function.

For more information about how the program draws the plot, see these entries:

(My next entry will show a new twist to this technique, but I promise that will be the last one on this subject for a while and I'll move on to something new.)

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.