| java.lang.Object edu.hws.jcm.draw.Drawable edu.hws.jcm.draw.RiemannSumRects
RiemannSumRects | public class RiemannSumRects extends Drawable implements Computable(Code) | | A RiemannSumRects calculates a Riemann sum for a function. It implements
Computable and InputObject. You can specify and change the number of
intervals in the sum, as well as the method used to calculate the sum.
Functions exist to return Value objects for the sum using different
computations. This class was written by Gabriel Weinstock, with some
modifications by David Eck
|
Constructor Summary | |
public | RiemannSumRects() Construct a RiemannSumRects object that initially has nothing to draw and that
is set up to use the default number of intervals, 5. | public | RiemannSumRects(Function f, Value i) Construct a new RiemannSumRects object.
Parameters: i - a Value object representing the number of intervals. |
Method Summary | |
public void | compute() This is generally called by a Controller. | public void | draw(Graphics g, boolean coordsChanged) Draw the Rieman sum rects. | public Color | getColor() | public Function | getFuction() Returns the function whose Riemann sums are computed. | public Value | getIntervalCount() Get the number of intervals used. | public int | getMethod() | public Color | getOutlineColor() Get the color that is used to draw outlines around the rects. | public Value | getValueObject(int which) Gets a Value object that gives the value of the Riemann sum for the specified method. | public void | setColor(Color c) Set the color used to draw the rectangles. | public void | setFunction(Function func) Set the function whose Riemann sums are to be computed. | public void | setIntervalCount(Value c) Set the interval count (the RiemannSumRects will be redrawn after this function
is called). | public void | setMethod(int m) Set the method used to calculate the rectangles. | public void | setOutlineColor(Color c) Set the color that will be used to draw outlines around the rects. |
CURRENT_METHOD | final public static int CURRENT_METHOD(Code) | | For use in getValueObject(), to indicate whatever summation method is currently set for drawing.
|
LEFTENDPOINTRIGHTENDPOINTMIDPOINTCIRCUMSCRIBEDINSCRIBEDTRAPEZOID | final public static int LEFTENDPOINTRIGHTENDPOINTMIDPOINTCIRCUMSCRIBEDINSCRIBEDTRAPEZOID(Code) | | Summation method type.
|
RiemannSumRects | public RiemannSumRects()(Code) | | Construct a RiemannSumRects object that initially has nothing to draw and that
is set up to use the default number of intervals, 5.
|
RiemannSumRects | public RiemannSumRects(Function f, Value i)(Code) | | Construct a new RiemannSumRects object.
Parameters: i - a Value object representing the number of intervals. If null, five intervals are used. Parameters: f - a Function object used to derive the Riemann sum. If null, nothing is drawn. |
compute | public void compute()(Code) | | This is generally called by a Controller. Indicates that all data should be recomputed
because input values that the data depends on might have changed.
|
draw | public void draw(Graphics g, boolean coordsChanged)(Code) | | Draw the Rieman sum rects. This is generally called by an object of class CoordinateRect
|
getColor | public Color getColor()(Code) | | Get the current color used to draw the rectangles
|
getFuction | public Function getFuction()(Code) | | Returns the function whose Riemann sums are computed. Can be null.
|
getIntervalCount | public Value getIntervalCount()(Code) | | Get the number of intervals used.
a Value object representing the number of intervals |
getMethod | public int getMethod()(Code) | | Return the current method used to find the rectangle sums
|
getOutlineColor | public Color getOutlineColor()(Code) | | Get the color that is used to draw outlines around the rects. If this is null, then
no outlines are drawn.
|
getValueObject | public Value getValueObject(int which)(Code) | | Gets a Value object that gives the value of the Riemann sum for the specified method.
a Value object representing the sum for the given method Parameters: which - integer stating the method used to derive the sum; one of theconstants LEFTENDPOINT, RIGHTENDPOINT, MIDPOINT, CIRCUMSCRIBED, INSCRIBED, TRAPEZOID, or CURRENT_METHOD. |
setColor | public void setColor(Color c)(Code) | | Set the color used to draw the rectangles. The default color is a light yellow.
|
setFunction | public void setFunction(Function func)(Code) | | Set the function whose Riemann sums are to be computed. If null, nothing is drawn.
The function, if non-null, must have arity 1, or an IllegalArgumentException is thrown.
|
setIntervalCount | public void setIntervalCount(Value c)(Code) | | Set the interval count (the RiemannSumRects will be redrawn after this function
is called). The value will be clamped to be a value between 1 and 5000.
If the value is null, the default number of intervals, five, is used.
Parameters: c - a Value object representing the interval count |
setMethod | public void setMethod(int m)(Code) | | Set the method used to calculate the rectangles.
Parameters: m - can be: LEFTENDPOINT, RIGHTENDPOINT, MIDPOINT, CIRCUMSCRIBED,INSCRIBED or TRAPEZOID (these are integers ranging from 0 to 5, respectively) |
setOutlineColor | public void setOutlineColor(Color c)(Code) | | Set the color that will be used to draw outlines around the rects. If this is null,
then no outlines are drawn. The default is a medium-dark red that looks brownish next to the default yellow fill color.
|
|
|