42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#include <string>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include "flugkurve03.h"
|
|
using namespace std;
|
|
|
|
|
|
void Vektor::mul(const float &skalar){
|
|
this->x *= skalar;
|
|
this->y *= skalar;
|
|
}
|
|
|
|
void Vektor::add(const Vektor &vec2) {
|
|
this->x += vec2.x;
|
|
this->y += vec2.y;
|
|
}
|
|
|
|
Koerper bewegeKoerper(const Koerper &korp, const Vektor &gesamtkraft,const float &dt) {
|
|
Koerper erg = {0, {0,0}, {0,0}};
|
|
// Berechnung der Beschleunigung aus der Kraft
|
|
const float xBeschleunigung = gesamtkraft.x / korp.masse;
|
|
const float yBeschleunigung = gesamtkraft.y / korp.masse;
|
|
|
|
// Ermittlung der neuen Geschwindigkeit
|
|
erg.geschwindigkeit.x = korp.geschwindigkeit.x + dt * xBeschleunigung;
|
|
erg.geschwindigkeit.y = korp.geschwindigkeit.y + dt * yBeschleunigung;
|
|
|
|
// Ermittlung der neuen Position
|
|
erg.position.x += korp.position.x + dt * erg.geschwindigkeit.x;
|
|
erg.position.y += korp.position.y + dt * erg.geschwindigkeit.y;
|
|
return erg;
|
|
}
|
|
|
|
void ausgabeKoerper(const Koerper &korp){
|
|
cout << "x = " << korp.position.x << "y = " << korp.position.y;
|
|
}
|
|
|
|
void ausgabeVektor(const Vektor &vec){
|
|
cout << "x = " << vec.x << endl;
|
|
cout << "y = " << vec.y << endl;
|
|
}
|