[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: 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 the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.