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 @Override
49 protected void drawShape(Graphics g, Matrix a) {
50 double dx = (xmax-xmin)/nx;
51 double dy = (ymax-ymin)/ny;
52 double x,x2=xmax-dx/2;
53 double y,y2=ymax-dy/2;
54 SPoint sp = new SPoint(0,0);
55 Vector vr = new Vector();
57 y = ymin;
58 while ( y < y2 ) {
59 xDir(g,a,y,vr,sp);
60 y = y + dy;
61 }
62 xDir(g,a,ymax,vr,sp);
63
64 x = xmin;
65 while ( x < x2 ) {
66 yDir(g,a,x,vr,sp);
67 x = x + dx;
68 }
69 yDir(g,a,xmax,vr,sp);
70 }
71
72
80 private void xDir(Graphics g,Matrix a, double y, Vector vr, SPoint sp) { double x = xmin;
82 double dx = (xmax-xmin)/nx;
83 int x1,y1,x2,y2;
84 a.transform(vr.set(x,y,f.f(x,y)),sp);
85 x1 = sp.getX();
86 y1 = sp.getY();
87
88 x += dx;
89 while ( x < xmax ) {
90 a.transform(vr.set(x,y,f.f(x,y)),sp);
91 x2 = sp.getX();
92 y2 = sp.getY();
93 g.drawLine(x1,y1,x2,y2);
94 x1 = x2; y1 = y2;
95 x += dx;
96 }
97 x = xmax;
98 a.transform(vr.set(x,y,f.f(x,y)),sp);
99 x2 = sp.getX();
100 y2 = sp.getY();
101 g.drawLine(x1,y1,x2,y2);
102 }
103
104
112 private void yDir(Graphics g,Matrix a, double x, Vector vr, SPoint sp) { double y = ymin;
114 double dy = (ymax-ymin)/ny;
115 int x1,y1,x2,y2;
116 a.transform(vr.set(x,y,f.f(x,y)),sp);
117 x1 = sp.getX();
118 y1 = sp.getY();
119
120 y += dy;
121 while ( y < ymax ) {
122 a.transform(vr.set(x,y,f.f(x,y)),sp);
123 x2 = sp.getX();
124 y2 = sp.getY();
125 g.drawLine(x1,y1,x2,y2);
126 x1 = x2; y1 = y2;
127 y += dy;
128 }
129 y = ymax;
130 a.transform(vr.set(x,y,f.f(x,y)),sp);
131 x2 = sp.getX();
132 y2 = sp.getY();
133 g.drawLine(x1,y1,x2,y2);
134 }
135 }
136