4 Commits
11 changed files with 81 additions and 39 deletions
+3
View File
@@ -1 +1,4 @@
1_Grundlagen/code/matrix.exe 1_Grundlagen/code/matrix.exe
.out
.exe
.a
+28
View File
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,3 @@
#include <iostream>
#define NUM 0 #define NUM 0
using namespace std; using namespace std;
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+24 -31
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;
} }
+19
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);