1 package fi.jyu.mit.graphics;
2
3 import java.awt.Graphics;
4
5
10 public class FunctionMapRR extends BasicShape {
11 private double xmin,xmax;
12 private FunctionRR f;
13 private double z = 0.0;
14
15
22 public FunctionMapRR(FunctionRR f, double xmin, double xmax, double z) {
23 this(f,xmin,xmax);
24 this.z = z;
25 }
26
27
33 public FunctionMapRR(FunctionRR f, double xmin, double xmax) {
34 super();
35 this.f = f;
36 this.xmin = xmin;
37 this.xmax = xmax;
38 }
39
40 @Override
41 protected void drawShape(Graphics g, Matrix a) {
42 double dx = (xmax-xmin)/1000;
43 SPoint sp = new SPoint(0,0);
44 Vector vr = new Vector(); int x1,y1,x2,y2;
46
47 a.transform(vr.set(xmin,f.f(xmin),z),sp);
48 x1 = sp.getX();
49 y1 = sp.getY();
50
51 for (double x = xmin+dx; x <= xmax; x+=dx) {
52 a.transform(vr.set(x,f.f(x),z),sp);
53 x2 = sp.getX();
54 y2 = sp.getY();
55 g.drawLine(x1,y1,x2,y2);
56 x1 = x2; y1 = y2;
57 }
58 a.transform(vr.set(xmax,f.f(xmax),z),sp);
59 x2 = sp.getX();
60 y2 = sp.getY();
61 g.drawLine(x1,y1,x2,y2);
62 }
63
64
78 public static double funMin(FunctionRR f,double x1, double x2, double dx) {
79 double fx,x,f_min = f.f(x2);
80 for (x = x1; x < x2; x+=dx) {
81 fx = f.f(x);
82 if ( fx < f_min ) f_min = fx;
83 }
84 return f_min;
85 }
86
87
101 public static double funMax(FunctionRR f,double x1, double x2, double dx) {
102 double fx,x,f_max=f.f(x2);
103 for (x = x1; x < x2; x+=dx) {
104 fx = f.f(x);
105 if ( fx > f_max ) f_max = fx;
106 }
107 return f_max;
108 }
109 }
110