44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#include "flugkurve01.h"
|
|
#include <iostream>
|
|
using namespace std;
|
|
#define Y_BESCHLEUNIGUNG_GRAVITATION 9.81
|
|
Vektor mulVektor(Vektor vec, float num) {
|
|
Vektor ergebnis = {vec.x * num, vec.y * num};
|
|
return ergebnis;
|
|
}
|
|
|
|
Vektor addVektor(Vektor vec1, Vektor vec2) {
|
|
Vektor erg = {vec1.x + vec2.x, vec1.y + vec2.y};
|
|
return erg;
|
|
}
|
|
|
|
Koerper bewegeKoerper(Koerper korp, Vektor gesamtkraft, float dt) {
|
|
cout << fixed;
|
|
cout.precision(2);
|
|
// Simulation:
|
|
for (;;) {
|
|
cout << "(" << korp.position.x << "," << korp.position.y << ")" << endl;
|
|
|
|
// Berechnung der Beschleunigung aus der Kraft
|
|
float xBeschleunigung =
|
|
korp.geschwindigkeit.x * korp.REIBUNGSKOEFFIZIENT / korp.masse +
|
|
korp.REIBUNGSKOEFFIZIENT;
|
|
float yBeschleunigung =
|
|
korp.geschwindigkeit.y * korp.REIBUNGSKOEFFIZIENT / korp.masse +
|
|
Y_BESCHLEUNIGUNG_GRAVITATION;
|
|
|
|
// Ermittlung der neuen Geschwindigkeit
|
|
korp.geschwindigkeit.x += dt * xBeschleunigung;
|
|
korp.geschwindigkeit.y += dt * yBeschleunigung;
|
|
|
|
// Ermittlung der neuen Position
|
|
korp.position.x += dt * korp.geschwindigkeit.x;
|
|
korp.position.y += dt * korp.geschwindigkeit.y;
|
|
|
|
if (korp.position.y <= 0) {
|
|
break;
|
|
}
|
|
}
|
|
return korp;
|
|
}
|