/* Plot.java Simple 2-D Plotting Canvas that can also plot some polynomials 20-July-1997 Author: Bryan Lewis Kent State University Department of Mathematics & Computer Science mail: blewis@mcs.kent.edu url: http://www.mcs.kent.edu/~blewis/ This software is in the public domain and can be used, modified and distributed without restriction. JVM 1.02 Needs the following objects: java.lang.*, Matrix, java.awt*, java.util.Vector, plotText Revisions: October, 98: Added a fixed plot scale option, a text component (plotText), a clear method September, 1998: Added aspect ratio control variable, plotStyle variable for lines or dots, multi-color plotting, addapted for plotting ellipses for dots. 11.August, 1997: Added quadratic, cubic models */ import java.awt.*; import java.lang.*; import java.util.Vector; class Plot extends Canvas { /* A generic 2D plotting canvas P = storage for data points to be plotted M = storage for the model data radii specifies plot colors and plot point radii: no columns: radius=2, color=blue One column: radius=2, color=specified Two columns: x-axis length, y axis length (default color) Three columns: x, y, color */ // coordinate system: public double xmax, xmin, ymax, ymin; public int xcenter, ycenter; public boolean autoScale=true; // change autoScale to false to set scale manually public Matrix P = new Matrix(); public Matrix M = new Matrix(); public Matrix radii = new Matrix(); public String plotStyle = new String("dots"); // change plotStyle to "lines" for connect-the-dots public boolean squareAspectRatio = false; // set squareAspectRatio to true for a square plot public Vector text=new Vector(); // A vector of plotText objects Plot() { super(); } public void clear(){ // clear this plot P=new Matrix(); M=new Matrix(); radii=new Matrix(); text=new Vector(); repaint(); } public void paint(Graphics g) { /* draw border, ticks, first checking coordinate system bounds */ int i, j; double r=1; if((radii.rows>0)&&(radii.columns>1)){ r = 2*radii.sub(0,radii.rows-1,0,Math.min(radii.columns-1,1)).max(); } if((autoScale)&&(P.columns>1)){ xmax=0;xmin=0;ymax=0;ymin=0; for(i=0; i