Compare commits

..

No commits in common. "be77aebb258392c51345dfaaf372f9448ea5bd75" and "7ae37fad48f67e7529a86a373e4544a55b4f306d" have entirely different histories.

4 changed files with 41 additions and 56 deletions

3
.gitignore vendored
View File

@ -1,4 +1 @@
1_Grundlagen/code/matrix.exe 1_Grundlagen/code/matrix.exe
.out
.exe
.a

Binary file not shown.

View File

@ -1,38 +1,45 @@
#include "flugkurve01.h"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
Vektor mulVektor(Vektor vec, float num) { int main()
Vektor ergebnis = {vec.x * num, vec.y * num}; {
return ergebnis; // Körper:
} float masse = 10; // [kg]
float xPosition = 0; // [m]
Vektor addVektor(Vektor vec1, Vektor vec2) { float yPosition = 0; // [m]
Vektor erg = {vec1.x + vec2.x, vec1.y + vec2.y}; float xGeschwindigkeit = 10; // [m/s]
return erg; float yGeschwindigkeit = 10; // [m/s]
}
// Parametrierung der auf den Körper wirkende Kräfte:
Koerper bewegeKoerper(Koerper korp, Vektor gesamtkraft, float dt) { const float X_BESCHLEUNIGUNG_GRAVITATION = 0; // [m/s^2]
const float Y_BESCHLEUNIGUNG_GRAVITATION = -9.81; // [m/s^2]
// Berechnung der Beschleunigung aus der Kraft const float REIBUNGSKOEFFIZIENT = -5; // [kg/s]
float xBeschleunigung = gesamtkraft.x / korp.masse;
float yBeschleunigung = gesamtkraft.y / korp.masse; // Sorgt dafür, dass 2 Nachkommastellen angezeigt werden:
cout << fixed;
// Ermittlung der neuen Geschwindigkeit cout.precision(2);
korp.geschwindigkeit.x += dt * xBeschleunigung;
korp.geschwindigkeit.y += dt * yBeschleunigung; // Simulation:
const float dt = 0.1; // [s]
// Ermittlung der neuen Position for(;;)
korp.position.x += dt * korp.geschwindigkeit.x; {
korp.position.y += dt * korp.geschwindigkeit.y; cout << "(" << xPosition << "," << yPosition << ")" << endl;
return korp;
} // Berechnung der Beschleunigung aus der Kraft
float xBeschleunigung = xGeschwindigkeit * REIBUNGSKOEFFIZIENT / masse + X_BESCHLEUNIGUNG_GRAVITATION;
void ausgabeKoerper(Koerper korp){ float yBeschleunigung = yGeschwindigkeit * REIBUNGSKOEFFIZIENT / masse + Y_BESCHLEUNIGUNG_GRAVITATION;
cout << "x = " << korp.position.x << "y = " << korp.position.y;
} // Ermittlung der neuen Geschwindigkeit
xGeschwindigkeit += dt * xBeschleunigung;
void ausgabeVektor(Vektor vec){ yGeschwindigkeit += dt * yBeschleunigung;
cout << "x = " << vec.x << endl;
cout << "y = " << vec.y << endl; // Ermittlung der neuen Position
xPosition += dt * xGeschwindigkeit;
yPosition += dt * yGeschwindigkeit;
if(yPosition<=0)
{
break;
}
}
} }

View File

@ -1,19 +0,0 @@
#pragma once
// Parametrierung der auf den Körper wirkende Kräfte:
struct Vektor {
float x; // [m/s^2]
float y; // [m/s^2]
};
// Körper:
struct Koerper {
float masse = 10; // [kg]
Vektor position;
Vektor geschwindigkeit;
};
Vektor addVektor(Vektor vec1, Vektor vec2);
Vektor mulVektor(Vektor vec, float skalar);
Koerper bewegeKoerper(Koerper korp, Vektor gesamtkraft, float dt);
void ausgabeKoerper(Koerper korp);
void ausgabeVektor(Vektor vec);