Hallo,
ich möchte die Flugbahn einer Kanonenkugel berechnen, die in einem bestimmten Winkel abgeschossen wird.
Dazu wollte ich jetzt folgende Formeln benutzen:
x = Anfangsgeschwindigkeit * cos(alpha) * t;
y = Anfangsgeschwindigkeit * sin(alpha) * t - g/2
Ich habe das mit einem Beispiel getestet:
Anfangsgeschwindigkeit: 1
alpha: 45°
t ist am Anfang null, wird bei jedem Timerdurchlauf um 1 erhöht
g = 9,81 gerundet 10
in Java sieht das bei mir dann so aus:
Der Vollständigkeit halber noch mal die ganze Klasse:
Mein Problem ist, dass ich da eher eine lineare Funktion als eine Prabel herausbekomme
ich möchte die Flugbahn einer Kanonenkugel berechnen, die in einem bestimmten Winkel abgeschossen wird.
Dazu wollte ich jetzt folgende Formeln benutzen:
x = Anfangsgeschwindigkeit * cos(alpha) * t;
y = Anfangsgeschwindigkeit * sin(alpha) * t - g/2
Ich habe das mit einem Beispiel getestet:
Anfangsgeschwindigkeit: 1
alpha: 45°
t ist am Anfang null, wird bei jedem Timerdurchlauf um 1 erhöht
g = 9,81 gerundet 10
in Java sieht das bei mir dann so aus:
Code:
public vector2d getCurrentpos(int t) {
double x = v0 * Math.cos(Math.toRadians(angle)) * t;
double y = v0 * Math.sin(Math.toRadians(angle)) * t - 5 * (t * t) * -1;
return new vector2d((int)x, (int)y);
}
Der Vollständigkeit halber noch mal die ganze Klasse:
Code:
public class Kanonenkugel {
private Timer timer;
private vector2d startpos, size, currenpos;
private int angle;
private int v0;
private int t = 0;
public Kanonenkugel(vector2d startpos, vector2d size, int angle, int v0) {
this.startpos = startpos;
this.currenpos = startpos;
this.size = size;
this.angle = angle;
this.v0 = v0;
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
System.out.println("xPos: " + currenpos.x()+ " yPos: " + currenpos.y());
currenpos = getCurrentpos(t);
t++;
}
}, 0, 100);
}
public vector2d getCurrentpos(int t) {
double x = v0 * Math.cos(Math.toRadians(angle)) * t;
double y = v0 * Math.sin(Math.toRadians(angle)) * t - 5 * (t * t) * -1;
return new vector2d((int)x, (int)y);
}
public vector2d getStartpos() {
return startpos;
}
public void setStartpos(vector2d startpos) {
this.startpos = startpos;
}
public vector2d getSize() {
return size;
}
public void setSize(vector2d size) {
this.size = size;
}
public vector2d getCurrenpos() {
return currenpos;
}
public void setCurrenpos(vector2d currenpos) {
this.currenpos = currenpos;
}
}
Mein Problem ist, dass ich da eher eine lineare Funktion als eine Prabel herausbekomme