_Nachtrag

Bug fix
This commit is contained in:
Kristoph Laemmerzahl 2025-11-09 17:29:05 +01:00
parent 3d346a3789
commit cb97261672
5 changed files with 51 additions and 24 deletions

Binary file not shown.

Binary file not shown.

View File

@ -9,6 +9,9 @@
// Matrixmultiplikation
// Rotationsmatrix um Achse x/y/z
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
@ -16,11 +19,14 @@ static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
//Mathematische Funkion, Rechnung (Matrix C = A*B)
//Matrixmultiplikation-Funktion
std::array<std::array<double,4>,4> gameMatrix::matmul(
const std::array<std::array<double,4>,4>& A,
const std::array<std::array<double,4>,4>& B)
{
{ //Matrix-Mathematik (Matrix C = A*B)
std::array<std::array<double,4>,4> C{};
for (int i = 0; i < 4; ++i)
@ -28,37 +34,44 @@ std::array<std::array<double,4>,4> gameMatrix::matmul(
for (int k = 0; k < 4; ++k)
C[i][j] += A[i][k] * B[k][j];
return C;
}
// -------------------- Translationsmatrix --------------------
std::array<std::array<double,4>,4> gameMatrix::translate(const std::array<double,3>& pos) {
std::array<std::array<double,4>,4> T{};
for (int i = 0; i < 4; ++i)
T[i][i] = 1.0; // Identitätsmatrix
T[0][3] = pos[0]; // x-Verschiebung
T[1][3] = pos[1]; // y-Verschiebung
T[2][3] = pos[2]; // z-Verschiebung
return T;
}
int main()
{
std::array<std::array<double,4>,4> A{};
std::array<std::array<double,4>,4> B{};
std::cout << "Gib die Werte für Matrix A (4x4) ein:\n";
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j) {
std::cout << "A[" << i << "][" << j << "] = ";
std::cin >> A[i][j];
}
std::cout << "\nGib die Werte für Matrix B (4x4) ein:\n";
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j) {
std::cout << "B[" << i << "][" << j << "] = ";
std::cin >> B[i][j];
}
auto C = gameMatrix::matmul(A, B);
// Beispiel: Translation testen
std::array<double,3> pos;
std::cout << "Gib die Translation (x y z) ein: ";
std::cin >> pos[0] >> pos[1] >> pos[2];
std::cout << "\nErgebnis der Matrixmultiplikation (C = A * B):\n";
std::array<std::array<double,4>,4> T = gameMatrix::translate(pos);
std::cout << "\nTranslationsmatrix T:\n";
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j)
std::cout << C[i][j] << "\t";
std::cout << T[i][j] << "\t";
std::cout << "\n";
}
return 0;
}

View File

@ -64,6 +64,20 @@ std::array<std::array<double,4>,4> gameMatrix::rot3D(double angle_deg, char axis
return R;
}
//Translation
std::array<std::array<double,4>,4> gameMatrix::translate(const std::array<double,3>& pos) {
std::array<std::array<double,4>,4> T{};
for (int i = 0; i < 4; ++i)
T[i][i] = 1.0; // Identitätsmatrix
T[0][3] = pos[0]; // x-Verschiebung
T[1][3] = pos[1]; // y-Verschiebung
T[2][3] = pos[2]; // z-Verschiebung
return T;
}
int main()

View File

@ -19,9 +19,9 @@ public:
char axis
);
// Verschiebung
// Translation
static std::array<std::array<double,4>,4> translate(
const std::array<double,
3>& pos);
const std::array<double,3>& pos
);
};