Compare commits

...

3 Commits

4 changed files with 56 additions and 41 deletions

3
.gitignore vendored
View File

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

BIN
2_Flugkurve01/code/flugkurve Executable file

Binary file not shown.

View File

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

View File

@ -0,0 +1,19 @@
#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);