Flugkurve V4
This commit is contained in:
parent
3eb8785027
commit
af8dca4694
83
flugkurve.cpp
Normal file
83
flugkurve.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* $Author: MahrTh $
|
||||
* $Rev: 118 $
|
||||
* $Date: 2015-03-21 21:39:51 +0100 (Sa, 21. Mär 2015) $
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Vektor {
|
||||
public:
|
||||
float x, y;
|
||||
|
||||
void add(Vektor vektor) {
|
||||
x += vektor.x;
|
||||
y += vektor.y;
|
||||
}
|
||||
void mul(float faktor) {
|
||||
x *= faktor;
|
||||
y *= faktor;
|
||||
}
|
||||
string text(){
|
||||
stringstream ss;
|
||||
ss << "(" << x << "," << y << ")";
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
class Koerper{
|
||||
public:
|
||||
Vektor position;
|
||||
Vektor geschwindigkeit;
|
||||
float masse;
|
||||
|
||||
Koerper(Vektor position, Vektor geschwindigkeit, float masse) {
|
||||
this->position = position;
|
||||
this->geschwindigkeit = geschwindigkeit;
|
||||
this->masse = masse;
|
||||
}
|
||||
Vektor lieferePosition() {
|
||||
return position;
|
||||
}
|
||||
Vektor liefereGeschwindigkeit() {
|
||||
return geschwindigkeit;
|
||||
}
|
||||
float liefereMasse() {
|
||||
return masse;
|
||||
}
|
||||
void bewegen(Vektor beschleunigung, float dt) {
|
||||
position.add({geschwindigkeit.x * dt, geschwindigkeit.y * dt});
|
||||
geschwindigkeit.add({beschleunigung.x * dt, beschleunigung.y * dt});
|
||||
}
|
||||
string text() {
|
||||
return position.text();
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
// Körper:
|
||||
const float MASSE = 10;
|
||||
const Vektor START_POSITION = {0,0};
|
||||
const Vektor START_GESCHWINDIGKEIT = {10,10};
|
||||
Koerper koerper = {START_POSITION,START_GESCHWINDIGKEIT,MASSE};
|
||||
// Parametrierung der auf den Körper wirkende Kräfte:
|
||||
const Vektor BESCHLEUNIGUNG_GRAVITATION = {0,-9.81}; // [m/s^2]
|
||||
const float REIBUNGSKOEFFIZIENT =-5; // [kg/s]
|
||||
// Simulation:
|
||||
const float dt = 0.1;
|
||||
for(;;) {
|
||||
cout << "Position des Koerpers: " << koerper.text() << endl;
|
||||
// Bestimmung der neuen Beschleunigung
|
||||
Vektor beschleunigung;
|
||||
beschleunigung = koerper.liefereGeschwindigkeit();
|
||||
beschleunigung.mul(REIBUNGSKOEFFIZIENT/koerper.liefereMasse());
|
||||
beschleunigung.add(BESCHLEUNIGUNG_GRAVITATION);
|
||||
// Ermittlung der neuen Position und neuen Geschwindigkeit
|
||||
koerper.bewegen(beschleunigung,dt);
|
||||
if(koerper.lieferePosition().y<=0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user