Java Reference
In-Depth Information
the complete equation for y:
Figure 4.2 shows the equations for a parabola in action.
Another advantage of parametric equations is that there is no problem drawing
curves that have more than one y value for a given x value. Consider drawing a
circle.
The equation for a circle with a radius of 1 is:
or
Handling the fact that two y values emerge for every x value is complicated. It's also
difficult to adjust these values to plot correctly within a Graphics object's height
and width. Polar coordinates make the function for a circle simpler:
These formulas are parametric equations that show x and y as functions of a new
parameter, theta. Theta represents the sweep of an arc that varies from 0 to 2 pi as a
circle is drawn. You can set the radius of a circle so that it will fit within the height h
and width w of a Graphics object. A handful of parametric equations suffice to
plot a circle within the bounds of a Graphics object:
Translating these equations into Java produces the circle shown in Figure 4.3.
Search WWH ::




Custom Search