fixed block

This commit is contained in:
Karl-Wilfried Zimmer 2024-07-21 19:12:47 +02:00
parent 4ef94d4cb2
commit 66ae828379
8 changed files with 92 additions and 10 deletions

View File

@ -23,5 +23,9 @@ int main(int argc, char **argv) {
std::cout<<vec<<std::endl; std::cout<<vec<<std::endl;
std::cout<<vec.len()<<std::endl; std::cout<<vec.len()<<std::endl;
std::cout<<block<<std::endl; std::cout<<block<<std::endl;
std::vector<LinAlg::Vector3> normals=block.getNormals();
for(LinAlg::Vector3 vector:normals){
std::cout<<vector<<std::endl;
}
return 0; return 0;
} }

View File

@ -6,6 +6,8 @@
#define BLOCK_BLOCK_H #define BLOCK_BLOCK_H
#include <LinAlg/vector3.h> #include <LinAlg/vector3.h>
#include <LinAlg/plane.h>
#include <vector>
namespace Volumes{ namespace Volumes{
class Block{ class Block{
@ -13,7 +15,8 @@ namespace Volumes{
Block(const LinAlg::Vector3& v1, double x, double y, double z): corners{v1, Block(const LinAlg::Vector3& v1, double x, double y, double z): corners{v1,
v1 + LinAlg::Vector3(x, 0, 0), v1 + LinAlg::Vector3(x, 0, 0),
v1 + LinAlg::Vector3(x, y, 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, y, z),
v1 + LinAlg::Vector3(x, 0, z), v1 + LinAlg::Vector3(x, 0, z),
v1 + LinAlg::Vector3(0, 0, z)}{}; v1 + LinAlg::Vector3(0, 0, z)}{};
@ -35,7 +38,12 @@ namespace Volumes{
return os; return os;
} }
std::vector<LinAlg::Vector3> getNormals();
LinAlg::Vector3 getNormal(u_int8_t index);
private: private:
LinAlg::Vector3 corners[8]; LinAlg::Vector3 corners[8];
}; };
} }

View File

@ -5,14 +5,13 @@
#ifndef VOLSVECS_MATRIX3_H #ifndef VOLSVECS_MATRIX3_H
#define VOLSVECS_MATRIX3_H #define VOLSVECS_MATRIX3_H
#include "LinAlg/matrixmxn.h"
namespace LinAlg{ namespace LinAlg{
class Matrix3{ class Matrix3: public Matrix<3,3>{
public: public:
private: private:
short static getIndex(int x, int y);
double elements[9];
}; };
} }

View File

@ -8,6 +8,9 @@
namespace LinAlg{ namespace LinAlg{
template<short m,short n> template<short m,short n>
class Matrix{ class Matrix{
public:
virtual ~Matrix()=default;
protected: protected:
int static getIndex(short x, short y){ int static getIndex(short x, short y){
@ -15,8 +18,8 @@ namespace LinAlg{
if(y>=n) return -2; if(y>=n) return -2;
return x+y*n; return x+y*n;
} }
private:
double _entris[m*n]; double _entries[m*n];
}; };
} }

22
include/LinAlg/plane.h Normal file
View File

@ -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

View File

@ -10,4 +10,42 @@ namespace Volumes{
LinAlg::Vector3 z= corners[7] - corners[0]; LinAlg::Vector3 z= corners[7] - corners[0];
return x.len()*y.len()*z.len(); return x.len()*y.len()*z.len();
} }
std::vector<LinAlg::Vector3> Block::getNormals() {
std::vector<LinAlg::Vector3> 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();
}
}
} }

View File

@ -4,7 +4,4 @@
#include "LinAlg/matrix3.h" #include "LinAlg/matrix3.h"
namespace LinAlg{ namespace LinAlg{
short Matrix3::getIndex(int x, int y) {
return x+y*3;
}
} }

11
src/plane.cpp Normal file
View File

@ -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;
}
}