net.sourceforge.webcompmath.draw
Class RiemannSumRects

java.lang.Object
  extended by java.awt.Component
      extended by net.sourceforge.webcompmath.draw.Drawable
          extended by net.sourceforge.webcompmath.draw.RiemannSumRects
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, Computable
Direct Known Subclasses:
WCMRiemannSumRectsBean

public class RiemannSumRects
extends Drawable
implements Computable

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

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int CIRCLE_FRONT
          Circle cross section with diameter along the base.
static int CIRCLE_REAR
          Circle cross section with diameter along the base.
static int CIRCUMSCRIBED
          Summation method type: circumscribed (maximum value on the rectangle's interval)
static int CURRENT_METHOD
          For use in getValueObject(), to indicate whatever summation method is currently set for drawing.
static int EQUILATERAL
          Equilateral triangle cross section with side along the base.
static int INSCRIBED
          Summation method type: inscribed (minimum value on the rectangle's interval)
static int ISOSCELES_HYP
          Right isosceles triangle cross section with hypotenuse along the base.
static int ISOSCELES_LEG
          Right isosceles triangle cross section with leg along the base.
static int LEFTENDPOINT
          Summation method type: left end point
protected  int lineWidth
          The width, in pixels, of the outlines of the rects.
static int MIDPOINT
          Summation method type: mid point
static int POLAR
          Circular segment used for polar areas
static int RECTANGLE
          Rectangle (or trapezoid) shape
static int RIGHTENDPOINT
          Summation method type: right end point
static int SEMICIRCLE
          Semicircle cross section with diameter along the base.
static int SQUARE_DIAG_FRONT
          Square cross section with diagonal along the base.
static int SQUARE_DIAG_REAR
          Square cross section with diagonal along the base.
static int SQUARE_SIDE
          Square cross section with side along the base.
static int TRAPEZOID
          Summation method type: trapezoid
static int WASHER_FRONT
          Front half of washer
static int WASHER_REAR
          Rear half of washer
 
Fields inherited from class net.sourceforge.webcompmath.draw.Drawable
canvas, coords
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
RiemannSumRects()
          Construct a RiemannSumRects object that initially has nothing to draw and that is set up to use the default number of intervals, 5.
RiemannSumRects(Function f, Function lf, Value i)
          Construct a new RiemannSumRects object.
RiemannSumRects(Function f, Value i)
          Construct a new RiemannSumRects object.
 
Method Summary
 void compute()
          This is generally called by a Controller.
 void draw(java.awt.Graphics g, boolean coordsChanged)
          Draw the Rieman sum rects.
 java.awt.Color getColor()
          Get the current (positive) color used to draw the rectangles
 Function getFuction()
          Returns the function whose Riemann sums are computed.
 Value getIntervalCount()
          Get the number of intervals used.
 int getLineWidth()
          Get the width, in pixels, of lines that are drawn.
 Function getLowerFuction()
          Returns the lower function.
 int getMethod()
          Return the current method used to find the rectangle sums
 java.awt.Color getNegFillColor()
          Get the negative fill color
 java.awt.Color getNegOutlineColor()
          Get the negative outline color
 java.awt.Color getOutlineColor()
          Get the (positive) color that is used to draw outlines around the rects.
 java.awt.Color getPosFillColor()
          Get the positive fill color
 java.awt.Color getPosOutlineColor()
          Get the positive outline color
 int getShape()
          Get the shape for the Riemann sum.
 Value getValueObject(int which)
          Gets a Value object that gives the value of the Riemann sum for the specified method.
 Value getXMax()
          Get the max x value
 Value getXMin()
          Get the min x value
 boolean isInverse()
          Get whether to display inverse version
 void setColor(java.awt.Color c)
          Set the color used to draw the rectangles.
 void setFunction(Function func)
          Set the function whose Riemann sums are to be computed.
 void setIntervalCount(Value c)
          Set the interval count (the RiemannSumRects will be redrawn after this function is called).
 void setInverse(boolean inverse)
          Set whether to show as inverse.
 void setLineWidth(int width)
          Set the width, in pixels, of lines that are drawn.
 void setLowerFunction(Function func)
          Set the lower function, when computing area between curves.
 void setMethod(int m)
          Set the method used to calculate the rectangles.
 void setNegFillColor(java.awt.Color negFillColor)
          Set the negative fill color.
 void setNegOutlineColor(java.awt.Color negOutlineColor)
          Set the negative outline color.
 void setOutlineColor(java.awt.Color c)
          Set the color that will be used to draw outlines around the rects.
 void setPosFillColor(java.awt.Color posFillColor)
          Set the positive fill color
 void setPosOutlineColor(java.awt.Color posOutlineColor)
          Set the positive outline color
 void setShape(int shape)
          Set the shape for the Riemann sum.
 void setXMax(Value max)
          Set the max x value.
 void setXMin(Value min)
          Set the min x value.
 
Methods inherited from class net.sourceforge.webcompmath.draw.Drawable
getVisible, needsRedraw, setOwnerData, setVisible
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lineWidth

protected int lineWidth
The width, in pixels, of the outlines of the rects. It is restricted to being an integer in the range from 0 to 10. A value of 0 means that lines won't be drawn at all; this would only be useful for a filled rectangle that has a colored interior.


LEFTENDPOINT

public static final int LEFTENDPOINT
Summation method type: left end point

See Also:
Constant Field Values

RIGHTENDPOINT

public static final int RIGHTENDPOINT
Summation method type: right end point

See Also:
Constant Field Values

MIDPOINT

public static final int MIDPOINT
Summation method type: mid point

See Also:
Constant Field Values

CIRCUMSCRIBED

public static final int CIRCUMSCRIBED
Summation method type: circumscribed (maximum value on the rectangle's interval)

See Also:
Constant Field Values

INSCRIBED

public static final int INSCRIBED
Summation method type: inscribed (minimum value on the rectangle's interval)

See Also:
Constant Field Values

TRAPEZOID

public static final int TRAPEZOID
Summation method type: trapezoid

See Also:
Constant Field Values

CURRENT_METHOD

public static final int CURRENT_METHOD
For use in getValueObject(), to indicate whatever summation method is currently set for drawing.

See Also:
Constant Field Values

RECTANGLE

public static final int RECTANGLE
Rectangle (or trapezoid) shape

See Also:
Constant Field Values

WASHER_FRONT

public static final int WASHER_FRONT
Front half of washer

See Also:
Constant Field Values

WASHER_REAR

public static final int WASHER_REAR
Rear half of washer

See Also:
Constant Field Values

SQUARE_SIDE

public static final int SQUARE_SIDE
Square cross section with side along the base.

See Also:
Constant Field Values

SQUARE_DIAG_FRONT

public static final int SQUARE_DIAG_FRONT
Square cross section with diagonal along the base.

See Also:
Constant Field Values

SQUARE_DIAG_REAR

public static final int SQUARE_DIAG_REAR
Square cross section with diagonal along the base.

See Also:
Constant Field Values

SEMICIRCLE

public static final int SEMICIRCLE
Semicircle cross section with diameter along the base.

See Also:
Constant Field Values

CIRCLE_FRONT

public static final int CIRCLE_FRONT
Circle cross section with diameter along the base.

See Also:
Constant Field Values

CIRCLE_REAR

public static final int CIRCLE_REAR
Circle cross section with diameter along the base.

See Also:
Constant Field Values

EQUILATERAL

public static final int EQUILATERAL
Equilateral triangle cross section with side along the base.

See Also:
Constant Field Values

ISOSCELES_HYP

public static final int ISOSCELES_HYP
Right isosceles triangle cross section with hypotenuse along the base.

See Also:
Constant Field Values

ISOSCELES_LEG

public static final int ISOSCELES_LEG
Right isosceles triangle cross section with leg along the base.

See Also:
Constant Field Values

POLAR

public static final int POLAR
Circular segment used for polar areas

See Also:
Constant Field Values
Constructor Detail

RiemannSumRects

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.


RiemannSumRects

public RiemannSumRects(Function f,
                       Value i)
Construct a new RiemannSumRects object.

Parameters:
i - a Value object representing the number of intervals. If null, five intervals are used.
f - a Function object used to derive the Riemann sum. If null, nothing is drawn.

RiemannSumRects

public RiemannSumRects(Function f,
                       Function lf,
                       Value i)
Construct a new RiemannSumRects object.

Parameters:
f - a Function object used to derive the Riemann sum. If null, nothing is drawn.
lf - the lower function, may be null to use the horizontal axis
i - a Value object representing the number of intervals. If null, five intervals are used.
Method Detail

getShape

public int getShape()
Get the shape for the Riemann sum.

Returns:
the shape

setShape

public void setShape(int shape)
Set the shape for the Riemann sum. The default is RECTANGLE.

Parameters:
shape - the shape to set

getColor

public java.awt.Color getColor()
Get the current (positive) color used to draw the rectangles

Returns:
rectangle color

setColor

public void setColor(java.awt.Color c)
Set the color used to draw the rectangles. The default color is a light yellow. Sets both the positive and negative colors

Parameters:
c - rectangle color

setOutlineColor

public void setOutlineColor(java.awt.Color c)
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. Sets both the positive and negative colors.

Parameters:
c - outline color

getOutlineColor

public java.awt.Color getOutlineColor()
Get the (positive) color that is used to draw outlines around the rects. If this is null, then no outlines are drawn.

Returns:
outline color

getNegFillColor

public java.awt.Color getNegFillColor()
Get the negative fill color

Returns:
the negFillColor

setNegFillColor

public void setNegFillColor(java.awt.Color negFillColor)
Set the negative fill color. Not used by POLAR shapes.

Parameters:
negFillColor - the negFillColor to set

getNegOutlineColor

public java.awt.Color getNegOutlineColor()
Get the negative outline color

Returns:
the negOutlineColor

setNegOutlineColor

public void setNegOutlineColor(java.awt.Color negOutlineColor)
Set the negative outline color. Not used by POLAR shapes.

Parameters:
negOutlineColor - the negOutlineColor to set

getPosFillColor

public java.awt.Color getPosFillColor()
Get the positive fill color

Returns:
the posFillColor

setPosFillColor

public void setPosFillColor(java.awt.Color posFillColor)
Set the positive fill color

Parameters:
posFillColor - the posFillColor to set

getPosOutlineColor

public java.awt.Color getPosOutlineColor()
Get the positive outline color

Returns:
the posOutlineColor

setPosOutlineColor

public void setPosOutlineColor(java.awt.Color posOutlineColor)
Set the positive outline color

Parameters:
posOutlineColor - the posOutlineColor to set

setFunction

public void setFunction(Function func)
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.

Parameters:
func - function to computer Riemann sum for

getFuction

public Function getFuction()
Returns the function whose Riemann sums are computed. Can be null.

Returns:
function to computer Riemann sum for

setLowerFunction

public void setLowerFunction(Function func)
Set the lower function, when computing area between curves. If null, then the horizontal axis is used. The function, if non-null, must have arity 1, or an IllegalArgumentException is thrown. Not used by POLAR shape.

Parameters:
func - lower function

getLowerFuction

public Function getLowerFuction()
Returns the lower function. Can be null.

Returns:
function to computer Riemann sum for

setMethod

public void setMethod(int m)
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) TRAPEZOID is not valid for POLAR shapes.

getMethod

public int getMethod()
Return the current method used to find the rectangle sums

Returns:
can be: LEFTENDPOINT, RIGHTENDPOINT, MIDPOINT, CIRCUMSCRIBED, INSCRIBED or TRAPEZOID (these are integers ranging from 0 to 5, respectively)

setLineWidth

public void setLineWidth(int width)
Set the width, in pixels, of lines that are drawn. This is also used for outlines of rects and ovals. If set to 0, the thinnest possible line is drawn.

Parameters:
width - line width

getLineWidth

public int getLineWidth()
Get the width, in pixels, of lines that are drawn. This is also used for outlines of rects and ovals.

Returns:
line width

compute

public void compute()
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.

Specified by:
compute in interface Computable

getIntervalCount

public Value getIntervalCount()
Get the number of intervals used.

Returns:
a Value object representing the number of intervals

setIntervalCount

public void setIntervalCount(Value c)
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

getXMax

public Value getXMax()
Get the max x value

Returns:
Returns the xMax.

setXMax

public void setXMax(Value max)
Set the max x value. If Double.NaN, then use the current xMax of the graph. For POLAR shapes, 2pi is used if this isn't set.

Parameters:
max - The xMax to set.

getXMin

public Value getXMin()
Get the min x value

Returns:
Returns the xMin.

setXMin

public void setXMin(Value min)
Set the min x value. If Double.NaN, then use the current xMin of the graph. For POLAR shapes, -2pi is used if this isn't set.

Parameters:
min - The xMin to set.

draw

public void draw(java.awt.Graphics g,
                 boolean coordsChanged)
Draw the Rieman sum rects. This is generally called by an object of class CoordinateRect

Specified by:
draw in class Drawable
Parameters:
g - graphics context
coordsChanged - true or false

getValueObject

public Value getValueObject(int which)
Gets a Value object that gives the value of the Riemann sum for the specified method.

Parameters:
which - integer stating the method used to derive the sum; one of the constants LEFTENDPOINT, RIGHTENDPOINT, MIDPOINT, CIRCUMSCRIBED, INSCRIBED, TRAPEZOID, or CURRENT_METHOD.
Returns:
a Value object representing the sum for the given method

isInverse

public boolean isInverse()
Get whether to display inverse version

Returns:
true if inverse

setInverse

public void setInverse(boolean inverse)
Set whether to show as inverse. Not supported by POLAR shape.

Parameters:
inverse - true for inverse