net.sourceforge.webcompmath.draw
Class RiemannSlice

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

public class RiemannSlice
extends Drawable
implements Computable

A RiemannSlice shows one slice in a Riemann sum, useful for area and volume applets. It can show a rectangle (for area Riemann sums), washer (for volumes of revolution), various geometric shapes (for volumes of known cross section) or a segment of a circle for polar area. The volume types are designed to give a 3d look.

Washers and some known cross section shapes come in two halves. You add the rear half to a DisplayCanvas before the other drawables, then add the front half at the end. This improves the 3d effect. You can use a partly transparent fill color (which is the default) to help enhance things.

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
          Slice method type: circumscribed (maximum value on the rectangle's interval)
static int EQUILATERAL
          Equilateral triangle cross section with side along the base.
static int INSCRIBED
          Slice 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
          Slice method type: left end point
protected  int lineWidth
          The width, in pixels, of the outlines of the rects.
static int MIDPOINT
          Slice method type: mid point
static int POLAR
          Circular segment used for polar areas
static int RECTANGLE
          Rectangle (or trapezoid) shape
static int RIGHTENDPOINT
          Slice 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
          Slice method type: trapezoid (only recommended for RECTANGLE shape)
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
RiemannSlice()
          Construct a RiemannSumRects object that initially has nothing to draw and that is set up to use the default number of intervals, 5.
RiemannSlice(Function uf, Function lf, Value coord, int method, int shape)
          Construct a new RiemannSlice object.
 
Method Summary
 void compute()
          This is generally called by a Controller.
 void draw(java.awt.Graphics g, boolean coordsChanged)
          Draw the Rieman slice.
 float getAspect()
          Get the aspect ratio
 Value getAxis()
          Get the axis of revolution
 Value getCoordinate()
          Get the coordinate where the slice is to be drawn.
 java.awt.Color getFillColor()
          Get the current fill color
 int getLineWidth()
          Get the width, in pixels, of outline lines.
 Function getLowerFuction()
          Returns the lower function.
 int getMethod()
          Return the current method used to draw the slice
 java.awt.Color getOutlineColor()
          Get the color that is used to draw outlines around the rects.
 int getShape()
          Get the shape for this slice.
 float getSlant()
          Get the amount of slant offset
 float getSliceWidth()
          Get the width of the slice, in pixels.
 Function getUpperFuction()
          Returns the upper function for the Riemann slice.
 Value getXMax()
          Get the max x value
 Value getXMin()
          Get the min x value
 boolean isInverse()
          Get whether to display inverse version
 void setAspect(float aspect)
          Set the aspect ration (width to height).
 void setAxis(Value axis)
          Set the axis of revolution.
 void setCoordinate(Value coordinate)
          Set the coordinate where the slice is to be drawn.
 void setFillColor(java.awt.Color c)
          Set the fill color.
 void setInverse(boolean inverse)
          Set whether to show as inverse.
 void setLineWidth(int width)
          Set the width, in pixels, of outline lines.
 void setLowerFunction(Function func)
          Set the lower function, when computing area between curves.
 void setMethod(int m)
          Set the method used to draw the slice.
 void setOutlineColor(java.awt.Color c)
          Set the color that will be used to draw outlines around the rects.
 void setShape(int shape)
          Set the shape for this slice.
 void setSlant(float slant)
          Set the slant offset.
 void setSliceWidth(float width)
          Set the width of the slice.
 void setUpperFunction(Function func)
          Set the upper function that defines the top of the slice.
 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
Slice method type: left end point

See Also:
Constant Field Values

RIGHTENDPOINT

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

See Also:
Constant Field Values

MIDPOINT

public static final int MIDPOINT
Slice method type: mid point

See Also:
Constant Field Values

CIRCUMSCRIBED

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

See Also:
Constant Field Values

INSCRIBED

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

See Also:
Constant Field Values

TRAPEZOID

public static final int TRAPEZOID
Slice method type: trapezoid (only recommended for RECTANGLE shape)

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

RiemannSlice

public RiemannSlice()
Construct a RiemannSumRects object that initially has nothing to draw and that is set up to use the default number of intervals, 5.


RiemannSlice

public RiemannSlice(Function uf,
                    Function lf,
                    Value coord,
                    int method,
                    int shape)
Construct a new RiemannSlice object.

Parameters:
uf - upper function
lf - the lower function, may be null to use the horizontal axis
coord - a Value object representing the coordinate where the slice is to be drawn
method - the sum method; default is LEFTENDPOINT
shape - the slice shape; default is RECTANGLE
Method Detail

getFillColor

public java.awt.Color getFillColor()
Get the current fill color

Returns:
fill color

setFillColor

public void setFillColor(java.awt.Color c)
Set the fill color. The default color is a light grey, partly transparent.

Parameters:
c - fill 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 black.

Parameters:
c - outline color

getOutlineColor

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

Returns:
outline color

setUpperFunction

public void setUpperFunction(Function func)
Set the upper function that defines the top of the slice. If null, nothing is drawn. The function, if non-null, must have arity 1, or an IllegalArgumentException is thrown. For POLAR shapes, this gives r as a function of theta.

Parameters:
func - function for top of slice

getUpperFuction

public Function getUpperFuction()
Returns the upper function for the Riemann slice. Can be null.

Returns:
upper function

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 for POLAR shapes.

Parameters:
func - lower function

getLowerFuction

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

Returns:
lower function

setMethod

public void setMethod(int m)
Set the method used to draw the slice.

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.

getMethod

public int getMethod()
Return the current method used to draw the slice

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

getCoordinate

public Value getCoordinate()
Get the coordinate where the slice is to be drawn.

Returns:
the coordinate

setCoordinate

public void setCoordinate(Value coordinate)
Set the coordinate where the slice is to be drawn.

Parameters:
coordinate - the coordinate to set

getShape

public int getShape()
Get the shape for this slice.

Returns:
the shape

setShape

public void setShape(int shape)
Set the shape for this slice.

Parameters:
shape - the shape to set

getSliceWidth

public float getSliceWidth()
Get the width of the slice, in pixels.

Returns:
the width

setSliceWidth

public void setSliceWidth(float width)
Set the width of the slice. For all shapes except POLAR this is in pixels and must be > 0. If the width is 1, then the slice will be drawn with no width (i.e., just a line for rectangles, just a very thin washer). For POLAR shapes, this sets the width in degrees.

Parameters:
width - the width to set

setLineWidth

public void setLineWidth(int width)
Set the width, in pixels, of outline lines. Must be from 0 to 10. If set to 0, the thinnest possible line is drawn.

Parameters:
width - line width

getLineWidth

public int getLineWidth()
Get the width, in pixels, of outline lines.

Returns:
line width

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 applicable for POLAR shapes.

Parameters:
inverse - true for inverse

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

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

Parameters:
min - The xMin to set.

getAxis

public Value getAxis()
Get the axis of revolution

Returns:
the axis

setAxis

public void setAxis(Value axis)
Set the axis of revolution. Only valid for washer shapes.

Parameters:
axis - the axis to set

getAspect

public float getAspect()
Get the aspect ratio

Returns:
the aspect

setAspect

public void setAspect(float aspect)
Set the aspect ration (width to height). Default is 0.3. Only used for 3d-style shapes.

Parameters:
aspect - the aspect to set

getSlant

public float getSlant()
Get the amount of slant offset

Returns:
the slant

setSlant

public void setSlant(float slant)
Set the slant offset. This is from 0 to 1, with 0 being no slant and 1 being 45 degrees. The default is 0.1. Only used for 3d-style shapes.

Parameters:
slant - the slant to set

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

draw

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

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