inital commit. Set up all the exercises
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,82 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include "flugkurve03.h"
|
||||
using namespace std;
|
||||
|
||||
void function_checks() {
|
||||
// Vektor init
|
||||
Vektor test_vec = {10, 11};
|
||||
assert(fabs(test_vec.x - 10) < 0.1 && "x must be 10");
|
||||
assert(fabs(test_vec.y - 11) < 0.1 && "x must be 11");
|
||||
cout << "Vektor init erfolgreich" << endl;
|
||||
// Vektor mul
|
||||
test_vec.mul(2.0);
|
||||
assert(fabs(test_vec.x - 20) < 0.1 && "x must be 20");
|
||||
assert(fabs(test_vec.y - 22) < 0.1 && "x must be 22");
|
||||
cout << "Vektor mul erfolgreich" << endl;
|
||||
// Vektor add
|
||||
Vektor test_vec_2 = {1, 2};
|
||||
test_vec.add(test_vec_2);
|
||||
assert(fabs(test_vec.x - 21) < 0.1 && "x must be 21");
|
||||
assert(fabs(test_vec.y - 24) < 0.1 && "x must be 24");
|
||||
cout << "Vektor add erfolgreich" << endl;
|
||||
// Koerper init + getter
|
||||
float masse = 10;
|
||||
Vektor position = {2, 3};
|
||||
Vektor geschwindigkeit = {10, 11};
|
||||
Koerper koerper = {masse, position, geschwindigkeit};
|
||||
assert(fabs(koerper.liefereMasse() - 10) < 0.1 && "Mass must be 10");
|
||||
assert(fabs(koerper.lieferePosition().x - 2) < 0.1 && "Position: x must be 2");
|
||||
assert(fabs(koerper.lieferePosition().y - 3) < 0.1 && "Position: y must be 3");
|
||||
assert(fabs(koerper.liefereGeschwindigkeit().x - 10) < 0.1 && "Velocity: x must be 10");
|
||||
assert(fabs(koerper.liefereGeschwindigkeit().y - 11) < 0.1 && "Velocity: y must be 11");
|
||||
cout << "Koerper init + getter erfolgreich" << endl;
|
||||
// Koerper bewegen
|
||||
Vektor beschleunigung = {-2, -9};
|
||||
float dt = 0.1;
|
||||
koerper.bewegen(beschleunigung, dt);
|
||||
assert(fabs(koerper.liefereMasse() - 10) < 0.1 && "Mass must be 10");
|
||||
assert(fabs(koerper.lieferePosition().x - 2.98) < 0.1 && "Position: x must be 2.98");
|
||||
assert(fabs(koerper.lieferePosition().y - 4.01) < 0.1 && "Position: y must be 4.01");
|
||||
assert(fabs(koerper.liefereGeschwindigkeit().x - 9.8) < 0.1 && "Velocity: x must be 9.8");
|
||||
assert(fabs(koerper.liefereGeschwindigkeit().y - 10.1) < 0.1 && "Velocity: y must be 10.1");
|
||||
cout << "Koerper bewegen erfolgreich" << endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "Funktionsüberprüfung" << endl;
|
||||
|
||||
// Function checks
|
||||
function_checks();
|
||||
|
||||
// Check whole program
|
||||
cout << "Simulation" << endl;
|
||||
// Körper:
|
||||
const float MASSE = 10;
|
||||
const Vektor START_POSITION = {0,0};
|
||||
const Vektor START_GESCHWINDIGKEIT = {10,10};
|
||||
Koerper koerper(MASSE,START_POSITION,START_GESCHWINDIGKEIT);
|
||||
// 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 Körpers: " << 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "flugkurve03.h"
|
||||
using namespace std;
|
||||
|
||||
//to be implemented
|
||||
@@ -0,0 +1,4 @@
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
// to be defined
|
||||
Reference in New Issue
Block a user