//====================================================== // Numerical Analysis package in java // PlotShapes class // This class convert graphic draw methods to // plot coordinates and gives additional plotting methods // Dr. Turhan Coban // ===================================================== import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import java.awt.font.*; public class PlotShapesSW { public Graphics2D g; int xabsmin,yabsmin; int absheight,abswidth; double xmin,xmax,ymin,ymax; public int xlog,ylog; double xminmaxlog,yminmaxlog; Font f; final static float dash1[] = {10.0f}; final static float dash2[] = {10.0f,3.0f,3.0f}; final static float dash3[] = {10.0f,3.0f,3.0f}; final static float dash4[] = {5.0f,5.0f,5.0f}; final static BasicStroke d1 = new BasicStroke(1.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash1, 2.0f); final static BasicStroke d2 = new BasicStroke(1.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash2, 2.0f); final static BasicStroke d3 = new BasicStroke(1.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash3, 2.0f); final static BasicStroke d4 = new BasicStroke(1.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash4, 2.0f); final static BasicStroke d5 = new BasicStroke(2.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash1, 2.0f); final static BasicStroke d6 = new BasicStroke(2.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash2, 2.0f); final static BasicStroke d7 = new BasicStroke(2.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash3, 2.0f); final static BasicStroke d8 = new BasicStroke(2.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash4, 2.0f); /* public PlotShapesSW(Graphics2D gi,int xabsmini ,int yabsmini, int absheighti,int abswidthi, double xmini,double xmaxi, double ymini,double ymaxi) { // xabsmin : absulute stating point x axis // yabsmin : absolute starting point y axis // absheight : absoulute height of plotting window // abswidth : absolute width of plotting window // xmin : minimum x value (real number) // xmax : maximum x value (real number) // ymin : minimum y value (real number) // ymax : maximum y value (real number) // g : graphic object that actual drawing is done through g=gi; Font fonts[]=GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); f=fonts[2].deriveFont(Font.BOLD,14);//You can change Fony from here g.setFont(f); xabsmin=xabsmini; yabsmin=yabsmini; absheight=absheighti; abswidth=abswidthi; xmin=xmini; xmax=xmaxi; ymin=ymini; ymax=ymaxi; xlog=0; ylog=0; } */ public PlotShapesSW(Graphics2D gi,int xabsmini ,int yabsmini, int absheighti,int abswidthi, double xmini,double xmaxi, double ymini,double ymaxi, int xlogi,int ylogi) { // xabsmin : absulute starting point x axis // yabsmin : absolute starting point y axis // absheight : absoulute height of plotting window // abswidth : absolute width of plotting window // xmin : minimum x value (real number) // xmax : maximum x value (real number) // ymin : minimum y value (real number) // ymax : maximum y value (real number) // g : graphic object that actual drawing is done through g=gi; //Font fonts[]=GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); //f=fonts[2].deriveFont(Font.BOLD,14);//You can change Fony from here //g.setFont(f); xabsmin=xabsmini; yabsmin=yabsmini; absheight=absheighti; abswidth=abswidthi; xmin=xmini; xmax=xmaxi; ymin=ymini; ymax=ymaxi; xlog=xlogi; ylog=ylogi; if(xlog!=0) {xminmaxlog=Math.log10(xmax-xmin+10.0)-1.0;} if(ylog!=0) {yminmaxlog=Math.log10(ymax-ymin+10.0)-1.0;} } public void drawLine(int plottype,double x1,double y1,double x2,double y2) { // draw a line from (x1,y1) to (x2,y2) int xx1,xx2,yy1,yy2; if(xlog!=0) { xx1=(int)(xabsmin+((Math.log10(x1-xmin+10.0)-1.0)/xminmaxlog*abswidth)); xx2=(int)(xabsmin+((Math.log10(x2-xmin+10.0)-1.0)/xminmaxlog*abswidth)); } else { xx1=(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth); xx2=(int)(xabsmin+(x2-xmin)/(xmax-xmin)*abswidth); } if(ylog!=0) { yy1=(int)(yabsmin+absheight-((Math.log10(y1-ymin+10.0)-1.0)/yminmaxlog*absheight)); yy2=(int)(yabsmin+absheight-((Math.log10(y2-ymin+10.0)-1.0)/yminmaxlog*absheight)); } else { yy1=(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight); yy2=(int)(yabsmin+absheight-(y2-ymin)/(ymax-ymin)*absheight); } g.draw(new Line2D.Double( xx1,yy1,xx2,yy2)); } //end of drawLine public void drawPolyline(int plottype,double x1[],double y1[]) { // draw a line from (x1,y1) to (x2,y2) int points=y1.length; int xPoints[]=new int[points]; int yPoints[]=new int[points]; int xx1,yy1; for(int i=0;i=xmin && xi[i]<=xmax) && (yi[i]>=ymin && yi[i]<=ymax)) { drawStar(xi[i],yi[i],(int)(abswidth/80.0),5); } } } public void drawPlotLines(int i,int plottype[],double x[][],double y[][],int n[],char ch[]) { int j; //draw lines if((plottype[i] >= 0) && (plottype[i] < 10) ) { switch ( plottype[i] ) { case 0 : g.setStroke(new BasicStroke(1.0f));break; case 1 : g.setStroke(d1);break; case 2 : g.setStroke(d2);break; case 3 : g.setStroke(d3);break; case 4 : g.setStroke(d4);break; case 5 : g.setStroke(new BasicStroke(2.0f));break; case 6 : g.setStroke(d5);break; case 7 : g.setStroke(d6);break; case 8 : g.setStroke(d7);break; case 9 : g.setStroke(d8);break; }; for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { if((x[i][j+1]>=xmin && x[i][j+1]<=xmax) && (y[i][j+1]>=ymin && y[i][j+1]<=ymax)) { drawLine(0,x[i][j],y[i][j],x[i][j+1],y[i][j+1]); } else if(x[i][j+1]>xmax) { double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]); double a=y[i][j]-b*x[i][j]; drawLine(0,x[i][j],y[i][j],xmax,(a+b*xmax)); } else if(y[i][j+1]>ymax) { double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]); double a=y[i][j]-b*x[i][j]; drawLine(0,x[i][j],y[i][j],(ymax-a)/b,ymax); } else if(x[i][j+1]>xmax && y[i][j+1]>ymax) { double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]); double a=y[i][j]-b*x[i][j]; drawLine(0,x[i][j],y[i][j],(ymax-a)/b,(a+b*xmax)); } } else if((x[i][j+1]>=xmin && x[i][j+1]<=xmax ) && (y[i][j+1]>=ymin && y[i][j+1]<=ymax)) { if(x[i][j]=10 && plottype[i]<=19) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { drawChar(ch[i],x[i][j],y[i][j]); } }//end of for(j=0; }//end else if(plottype[i]==10..19) //draw rectangles else if(plottype[i]==20) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { drawRect(x[i][j],y[i][j],abswidth/100,abswidth/80); } }//end of for(j=0; }//end else if(plottype[i]==20) else if(plottype[i]==21) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { fillRect(x[i][j],y[i][j],abswidth/100,abswidth/80); } }//end of for(j=0; }//end else if(plottype[i]==20) //draw circle else if(plottype[i]==22) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { drawEllipse(x[i][j],y[i][j],abswidth/100,abswidth/80); } }//end of for(j=0; }//end else if(plottype[i]==22) else if(plottype[i]==23) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { fillEllipse(x[i][j],y[i][j],abswidth/100,abswidth/80); } }//end of for(j=0; }//end else if(plottype[i]==21) else if(plottype[i]>=24 && plottype[i]<=27) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { drawPolygon(x[i][j],y[i][j],abswidth/100,(plottype[i]-21)); } }//end of for(j=0; }//end else if(plottype[i]==24..27) else if(plottype[i]>=28 && plottype[i]<=31) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { fillPolygon(x[i][j],y[i][j],abswidth/100,(plottype[i]-25)); } }//end of for(j=0; }//end else if(plottype[i]==24..27) else if(plottype[i]>=32 && plottype[i]<=35) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { drawStar(x[i][j],y[i][j],abswidth/100,(plottype[i]-29)); } }//end of for(j=0; } else if(plottype[i]>=36 && plottype[i]<=39) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { fillStar(x[i][j],y[i][j],abswidth/100,(plottype[i]-33)); } }//end of for(j=0; } else if(plottype[i]==40) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { drawBar(x[i][j],y[i][j]); } }//end of for(j=0; } else if(plottype[i]==41) { for(j=0;j=xmin && x[i][j]<=xmax ) && (y[i][j]>=ymin && y[i][j]<=ymax)) { fillBar(x[i][j],y[i][j]); } }//end of for(j=0; } } }