A Fractal Generator

Team Fly 

Page 602

DEALING WITH SINGULARITIES

One issue that deserves attention is the handling of singularities. Singularities are points at which a function can't be calculated. Consider the function Cos(X) / X. This function can be plotted in any range that doesn't contain the point 0. If you attempt to calculate the function at X = 0, the result is an undefined number (NaN). If you run into a singularity, you can either ignore it and continue, or abort the process and inform the user that the function can't be plotted. In our code, we abort the process.

However, it's possible to skip the singularity, even though it's included in the range of X values. If the size of the PictureBox control is 200 pixels and you're plotting a function in the range from –2 to 2, you'll be calculating the function at increments of 4 / 200, which is 0.02. The points at which the function is calculated are : –2, –1.98, –1.96, and so on up to –0.02, 0, 0.02. When you attempt to calculate the function at point 0, you'll run into a singularity. If the PictureBox control's width were 285 pixels, however, the step along the X axis would be 4 / 285, or 0.014035087. The function will be evaluated at the point –0.00701754 and then at 0.00701754. The function can be evaluated at both points and the singularity has been skipped with no special effort on our part. Usually, it's the responsilibity of the user to avoid singularities in the range of X values and specify a meaningful X range for the plot.

In the second half of this chapter we're going to look at fractals. Fractals are special plots that aren't plotted with curves; instead, they fill the space with intricate patterns.

A Fractal Generator

People who start playing around with fractals sometimes get hooked. Fractals are like alien worlds—obviously different from things we see in nature, yet also somehow familiar. You can zoom into a fractal endlessly, producing fascinating variations of color, texture, and shape. And what you see as you take this tour somehow looks not only natural, like a cabbage or a tree, but also mysterious enough to earn fractals their reputation as the most complex objects in all math.

In this section we're going to demonstrate how you can generate fractals in VB. Beyond that, we'll also attempt to explain to nonmathematicians the strange numbers and odd dimensions that produce fractals. Mathematicians like fractals because they produce images of often startling beauty. Most mathematical formulae, when plotted, result in wave-like lines, arcs, and other visually simple—really rather boring—geometric designs. Fractals, by contrast, yield extremely complex, lacy, colorful patterns that hover just beyond symmetry. You never really see the same thing twice, though at first you might think so. Fractals often imitate the patterns found in nature—those produced, say, when a coastline erodes, or when an octopus grows a tentacle.

What Is a Fractal?

One way of describing a fractal is the adventures of a small number on the complex plane. A fractal is a peculiar and very dense ''graph" generated by a mathematical process. Although the resulting images are literally infinitely complex, the underlying algorithms are short and rather simple. When you want to see relationships between numbers—to see mathematical expressions—you can put them into a kind of grid called a plot. The coordinates of this space are arbitrary—that is, you can set up the marks to be large enough to embrace whatever expression you are trying to make visual. You saw how to scale the plot of an arbitrary function to fill a given area in the example of the first part of the chapter.

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net