1 package fi.jyu.mit.graphics;
2
3 import java.awt.Graphics;
4
5
10 public class FunctionMapR2R extends BasicShape {
11 private double xmin,ymin,xmax,ymax;
12 private int nx,ny;
13 private FunctionR2R f;
14
15
25 public FunctionMapR2R(FunctionR2R f, double xmin, double ymin, double xmax, double ymax,int nx, int ny) {
26 super();
27 this.f = f;
28 this.xmin = xmin;
29 this.ymin = ymin;
30 this.xmax = xmax;
31 this.ymax = ymax;
32 this.nx = nx;
33 this.ny = ny;
34 }
35
36
44 public FunctionMapR2R(FunctionR2R f, double xmin, double ymin, double xmax, double ymax) {
45 this(f,xmin,ymin,xmax,ymax,40,40);
46 }
47
48 protected void drawShape(Graphics g, Matrix a) {
49 double dx = (xmax-xmin)/nx;
50 double dy = (ymax-ymin)/ny;
51 double x,x2=xmax-dx/2;
52 double y,y2=ymax-dy/2;
53 SPoint sp = new SPoint(0,0);
54 Vector vr = new Vector();
56 y = ymin;
57 while ( y < y2 ) {
58 xDir(g,a,y,vr,sp);
59 y = y + dy;
60 }
61 xDir(g,a,ymax,vr,sp);
62
63 x = xmin;
64 while ( x < x2 ) {
65 yDir(g,a,x,vr,sp);
66 x = x + dx;
67 }
68 yDir(g,a,xmax,vr,sp);
69 }
70
71
79 private void xDir(Graphics g,Matrix a, double y, Vector vr, SPoint sp) { double x = xmin;
81 double dx = (xmax-xmin)/nx;
82 int x1,y1,x2,y2;
83 a.transform(vr.set(x,y,f.f(x,y)),sp);
84 x1 = sp.getX();
85 y1 = sp.getY();
86
87 x += dx;
88 while ( x < xmax ) {
89 a.transform(vr.set(x,y,f.f(x,y)),sp);
90 x2 = sp.getX();
91 y2 = sp.getY();
92 g.drawLine(x1,y1,x2,y2);
93 x1 = x2; y1 = y2;
94 x += dx;
95 }
96 x = xmax;
97 a.transform(vr.set(x,y,f.f(x,y)),sp);
98 x2 = sp.getX();
99 y2 = sp.getY();
100 g.drawLine(x1,y1,x2,y2);
101 }
102
103
111 private void yDir(Graphics g,Matrix a, double x, Vector vr, SPoint sp) { double y = ymin;
113 double dy = (ymax-ymin)/ny;
114 int x1,y1,x2,y2;
115 a.transform(vr.set(x,y,f.f(x,y)),sp);
116 x1 = sp.getX();
117 y1 = sp.getY();
118
119 y += dy;
120 while ( y < ymax ) {
121 a.transform(vr.set(x,y,f.f(x,y)),sp);
122 x2 = sp.getX();
123 y2 = sp.getY();
124 g.drawLine(x1,y1,x2,y2);
125 x1 = x2; y1 = y2;
126 y += dy;
127 }
128 y = ymax;
129 a.transform(vr.set(x,y,f.f(x,y)),sp);
130 x2 = sp.getX();
131 y2 = sp.getY();
132 g.drawLine(x1,y1,x2,y2);
133 }
134 }
135