Java Reference
In-Depth Information
Figure 27.4. The
FunPanel
class accepts
x
and
y
functions to plot.
The
setXY()
method in the
FunPanel
class accepts
x
and
y
functions and calculates
the minimum and maximum values of these curves:
public void setXY(Function fx, Function fy)
{
this.fx = fx;
this.fy = fy;
calculateExtrema();
repaint();
}
The functions that the
setXY()
method accepts are parametric functions of time. Any code
that works with the curve of a function will evaluate the function as time varies from 0 to 1.
We shall see that this approach will let us plot parabolas, circles, and other types of curves for
which
y
is not strictly a function of
x
. The idea that time varies from 0 to 1 appears several
places in the function-plotting code, such as the calculation of the extreme values of the
functions: