import java.awt.*; import java.util.*; import java.lang.*; import java.text.*; public class graphUtil{ private static final double one=1.0e0; private static final int Itwo=2; private double clipFactor; private int Umin, Umax, Vmin, Vmax; private int UMIN, UMAX, VMIN, VMAX; private double V1[] = new double[20]; graphUtil(){ setClipFactor(0.9e0); } public int[] get2DWindowLimits(){ int v[] = new int[4]; v[0] = UMIN; v[1] = UMAX; v[2] = VMIN; v[3] = VMAX; return(v); } public void ViewportWindowBounds(int Mx, int My, double xleft, double ybottom, double xright, double ytop) { int delta, deltaX, deltaY, Side, zero=0, two=2; delta = Math.abs(Mx - My); Side = Math.min(Mx, My); if(Mx > My){ deltaX = delta / two; deltaY = zero; }else if(My > Mx){ deltaX = zero; deltaY = delta / two ; }else{ deltaX = deltaY = zero; } UMIN = (int)(Side * xleft + deltaX); UMAX = (int)(Mx - deltaX - xright * Side); VMIN = (int)(Side * ytop + deltaY); VMAX = (int)(My - deltaY - ybottom * Side); return; } public void DrawFrame(Graphics g, boolean BiggerFrame) { //Define slightly larger bounds for frame so that lines drawn //do not overlap it if(BiggerFrame){ Umin = UMIN - 2; Umax = UMAX + 2; Vmin = VMIN - 2; Vmax = VMAX + 2; g.drawLine(Umin, Vmin, Umin, Vmax); g.drawLine(Umin, Vmax, Umax, Vmax); g.drawLine(Umax, Vmax, Umax, Vmin); g.drawLine(Umax, Vmin, Umin, Vmin); return; }else{ g.drawLine(UMIN, VMIN, UMIN, VMAX); g.drawLine(UMIN, VMAX, UMAX, VMAX); g.drawLine(UMAX, VMAX, UMAX, VMIN); g.drawLine(UMAX, VMIN, UMIN, VMIN); } return; } //For a window delimited by diagonal corners (UMIN, VMIN) //and (UMAX, VMAX), set a clipping rectangle inside these //bounds. public void setClipRectangle(Graphics g) { int deltax = UMAX - UMIN; int deltay = VMAX - VMIN; int Wclip = (int)(clipFactor*deltax); int Hclip = (int)(clipFactor*deltay); int shiftedX = (int)((one - clipFactor)*(double)deltax) / Itwo; int shiftedY = (int)((one - clipFactor)*(double)deltay) / Itwo; shiftedX += UMIN; shiftedY += VMIN; g.clipRect(shiftedX, shiftedY, Wclip, Hclip); } //Set the fraction of the window that will be visible. A factor //of 1 implies that everything inside the window will be visible. public void setClipFactor(double clipFactor) { this.clipFactor = clipFactor; } // Assuming that coordinate vectors "x" are arranged in rows, // but T is the transformation matrix for the "x" arranged in // columns, compute: X' = X.(T)T to output transformed "x'" in rows. public void TransformCoord2D(int n, double X[][], double T[][]) { int i, j, k; double zero=0.0e0; for(i=0; i