From 66ae828379ca0325513145eb1dbe37a682cabd03 Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Sun, 21 Jul 2024 19:12:47 +0200 Subject: [PATCH] fixed block --- apps/main.cpp | 4 ++++ include/Block/block.h | 10 +++++++++- include/LinAlg/matrix3.h | 7 +++---- include/LinAlg/matrixmxn.h | 7 +++++-- include/LinAlg/plane.h | 22 ++++++++++++++++++++++ src/block.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/matrix3.cpp | 3 --- src/plane.cpp | 11 +++++++++++ 8 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 include/LinAlg/plane.h create mode 100644 src/plane.cpp diff --git a/apps/main.cpp b/apps/main.cpp index 38fa874..e4b0f54 100644 --- a/apps/main.cpp +++ b/apps/main.cpp @@ -23,5 +23,9 @@ int main(int argc, char **argv) { std::cout< normals=block.getNormals(); + for(LinAlg::Vector3 vector:normals){ + std::cout< +#include +#include namespace Volumes{ class Block{ @@ -13,7 +15,8 @@ namespace Volumes{ Block(const LinAlg::Vector3& v1, double x, double y, double z): corners{v1, v1 + LinAlg::Vector3(x, 0, 0), v1 + LinAlg::Vector3(x, y, 0), - v1 + LinAlg::Vector3(0, y, z), v1, + v1 + LinAlg::Vector3(0, y, 0), + v1+ LinAlg::Vector3(0, y, z), v1 + LinAlg::Vector3(x, y, z), v1 + LinAlg::Vector3(x, 0, z), v1 + LinAlg::Vector3(0, 0, z)}{}; @@ -35,7 +38,12 @@ namespace Volumes{ return os; } + std::vector getNormals(); + + LinAlg::Vector3 getNormal(u_int8_t index); + private: + LinAlg::Vector3 corners[8]; }; } diff --git a/include/LinAlg/matrix3.h b/include/LinAlg/matrix3.h index d93334c..e227237 100644 --- a/include/LinAlg/matrix3.h +++ b/include/LinAlg/matrix3.h @@ -5,14 +5,13 @@ #ifndef VOLSVECS_MATRIX3_H #define VOLSVECS_MATRIX3_H +#include "LinAlg/matrixmxn.h" + namespace LinAlg{ - class Matrix3{ + class Matrix3: public Matrix<3,3>{ public: private: - short static getIndex(int x, int y); - - double elements[9]; }; } diff --git a/include/LinAlg/matrixmxn.h b/include/LinAlg/matrixmxn.h index 45fc102..0081519 100644 --- a/include/LinAlg/matrixmxn.h +++ b/include/LinAlg/matrixmxn.h @@ -8,6 +8,9 @@ namespace LinAlg{ template class Matrix{ + public: + + virtual ~Matrix()=default; protected: int static getIndex(short x, short y){ @@ -15,8 +18,8 @@ namespace LinAlg{ if(y>=n) return -2; return x+y*n; } - private: - double _entris[m*n]; + + double _entries[m*n]; }; } diff --git a/include/LinAlg/plane.h b/include/LinAlg/plane.h new file mode 100644 index 0000000..2722c2e --- /dev/null +++ b/include/LinAlg/plane.h @@ -0,0 +1,22 @@ +// +// Created by nb on 21.07.24. +// + +#ifndef VOLSVECS_PLANE_H +#define VOLSVECS_PLANE_H + +#include "LinAlg/vector3.h" + +namespace LinAlg{ + class Plane{ + public: + Plane(const Vector3& a, const Vector3& b, const Vector3& c): _entries{a, b-a, c-a}{}; + + Vector3 getNormal(); + + virtual ~Plane()=default; + private: + Vector3 _entries[3]; + }; +} +#endif //VOLSVECS_PLANE_H diff --git a/src/block.cpp b/src/block.cpp index 91143ca..f73f366 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -10,4 +10,42 @@ namespace Volumes{ LinAlg::Vector3 z= corners[7] - corners[0]; return x.len()*y.len()*z.len(); } + + std::vector Block::getNormals() { + std::vector ret; + for(int i=0;i<6;i++) { + ret.push_back(getNormal(i)); + } + return ret; + } + + LinAlg::Vector3 Block::getNormal(u_int8_t index) { + switch(index){ + case 0:{ + LinAlg::Plane tmp(corners[1],corners[0],corners[2]); + return tmp.getNormal(); + }; + case 1:{ + LinAlg::Plane tmp(corners[3],corners[4],corners[2]); + return tmp.getNormal(); + } + case 2:{ + LinAlg::Plane tmp(corners[7],corners[4],corners[0]); + return tmp.getNormal(); + } + case 3:{ + LinAlg::Plane tmp(corners[5],corners[6],corners[2]); + return tmp.getNormal(); + } + case 4:{ + LinAlg::Plane tmp(corners[5],corners[4],corners[6]); + return tmp.getNormal(); + } + case 5:{ + LinAlg::Plane tmp(corners[6],corners[7],corners[1]); + return tmp.getNormal(); + } + default: return LinAlg::Vector3(); + } + } } \ No newline at end of file diff --git a/src/matrix3.cpp b/src/matrix3.cpp index 682209a..20f4698 100644 --- a/src/matrix3.cpp +++ b/src/matrix3.cpp @@ -4,7 +4,4 @@ #include "LinAlg/matrix3.h" namespace LinAlg{ - short Matrix3::getIndex(int x, int y) { - return x+y*3; - } } \ No newline at end of file diff --git a/src/plane.cpp b/src/plane.cpp new file mode 100644 index 0000000..388ba42 --- /dev/null +++ b/src/plane.cpp @@ -0,0 +1,11 @@ +// +// Created by nb on 21.07.24. +// +#include "LinAlg/plane.h" + +namespace LinAlg{ + Vector3 Plane::getNormal() { + Vector3 temp = (_entries[1].cross(_entries[2])).norm(); + return temp; + } +} \ No newline at end of file