Witam, próbuję napisać program, który rozwiązuje i rysuje wykres funkcji kwadratowej. Doszedłem do punktu, w którym nie mam pojęcia już co mam robić. Próbowałem naprawdę wielu rzeczy. Oto mój kod;
public class Wykres extends JPanel {
Interface i = new Interface();
JFrame o = i.okno;
double a = i.getliczbaa();
double b = i.getliczbab();
double c = i.getliczbac();
public double x = 0;
public double f(double x) {
return (a*x*x)+(b*x)+c;
}
public Wykres() {
setPreferredSize(new Dimension(800, 800));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
o.dispose();
Line2D osx = new Line2D.Double(0, 400, 800, 400);
Line2D osy = new Line2D.Double(400, 0, 400, 800);
g2d.draw(osx);
g2d.draw(osy);
//System.out.println(f(1));
double sizex = 800;
double sizey = 800;
int maxx = 10;
int minx = -10;
int maxy = 10;
int miny = -10;
double xunit = (maxx-minx)/sizex; //0,025
//System.out.println(xunit);
double yunit = (maxy-miny)/sizey;
int x0 = 400;
int y0 = 400;
while (x<801) {
double y = (f((x)*xunit)*yunit);
System.out.println(y);
double y2=(f((x+1)*xunit)*yunit);
//System.out.println(y);
Line2D w = new Line2D.Double(x, y, (x+1), y2);
g2d.draw(w);
x++;
System.out.println(x);
}
}
}