added matrix and changed namespace from vector to lingalg

This commit is contained in:
Karl-Wilfried Zimmer 2024-07-07 22:47:47 +02:00
parent e174292201
commit fff10699e6
8 changed files with 52 additions and 23 deletions

2
.idea/.name generated
View File

@ -1 +1 @@
block VolsVecs

View File

@ -3,8 +3,8 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
std::cout << "Hello, world!" << std::endl; std::cout << "Hello, world!" << std::endl;
Vector::Vector3 vec(1,2,3); LinAlg::Vector3 vec(1, 2, 3);
Vector::Vector3 vec2(2,1,3); LinAlg::Vector3 vec2(2, 1, 3);
Volumes::Block block(vec,1,1,1); Volumes::Block block(vec,1,1,1);
std::cout<<vec<<std::endl; std::cout<<vec<<std::endl;
std::cout<<vec.len()<<std::endl; std::cout<<vec.len()<<std::endl;

View File

@ -10,13 +10,13 @@
namespace Volumes{ namespace Volumes{
class Block{ class Block{
public: public:
Block(const Vector::Vector3& v1, double x, double y, double z):corners{v1, Block(const LinAlg::Vector3& v1, double x, double y, double z): corners{v1,
v1+Vector::Vector3(x,0,0), v1 + LinAlg::Vector3(x, 0, 0),
v1+Vector::Vector3(x,y,0), v1 + LinAlg::Vector3(x, y, 0),
v1+Vector::Vector3(0,y,z),v1, v1 + LinAlg::Vector3(0, y, z), v1,
v1+Vector::Vector3(x,y,z), v1 + LinAlg::Vector3(x, y, z),
v1+Vector::Vector3(x,0,z), v1 + LinAlg::Vector3(x, 0, z),
v1+Vector::Vector3(0,0,z)}{}; v1 + LinAlg::Vector3(0, 0, z)}{};
virtual ~Block() = default; virtual ~Block() = default;
double getVolume(); double getVolume();
@ -24,7 +24,7 @@ namespace Volumes{
friend std::ostream& operator<<(std::ostream& os, const Block& v){ friend std::ostream& operator<<(std::ostream& os, const Block& v){
os<<"["; os<<"[";
short count=0; short count=0;
for(Vector::Vector3 corner:v.corners){ for(LinAlg::Vector3 corner:v.corners){
count++; count++;
os<<corner; os<<corner;
if(count<8) { if(count<8) {
@ -36,7 +36,7 @@ namespace Volumes{
} }
private: private:
Vector::Vector3 corners[8]; LinAlg::Vector3 corners[8];
}; };
} }

19
include/LinAlg/matrix3.h Normal file
View File

@ -0,0 +1,19 @@
//
// Created by nb on 07.07.24.
//
#ifndef VOLSVECS_MATRIX3_H
#define VOLSVECS_MATRIX3_H
namespace LinAlg{
class Matrix3{
public:
private:
short static getIndex(int x, int y);
double elements[9];
};
}
#endif //VOLSVECS_MATRIX3_H

View File

@ -8,7 +8,7 @@
#include "iostream" #include "iostream"
#include <cmath> #include <cmath>
namespace Vector{ namespace LinAlg{
class Vector3{ class Vector3{
public: public:
Vector3(double x,double y, double z):x(x),y(y),z(z){}; Vector3(double x,double y, double z):x(x),y(y),z(z){};

View File

@ -5,9 +5,9 @@
namespace Volumes{ namespace Volumes{
double Block::getVolume() { double Block::getVolume() {
Vector::Vector3 x=corners[1]-corners[0]; LinAlg::Vector3 x= corners[1] - corners[0];
Vector::Vector3 y=corners[3]-corners[0]; LinAlg::Vector3 y= corners[3] - corners[0];
Vector::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();
} }
} }

10
src/matrix3.cpp Normal file
View File

@ -0,0 +1,10 @@
//
// Created by nb on 07.07.24.
//
#include "LinAlg/matrix3.h"
namespace LinAlg{
short Matrix3::getIndex(int x, int y) {
return x+y*3;
}
}

View File

@ -1,22 +1,22 @@
#include "Vector/vector3.h" #include "Vector/vector3.h"
namespace Vector{ namespace LinAlg{
Vector3 Vector3::operator+(const Vector::Vector3 &v) const { Vector3 Vector3::operator+(const LinAlg::Vector3 &v) const {
return {x+v.x,y+v.y,z+v.z}; return {x+v.x,y+v.y,z+v.z};
} }
Vector3& Vector3::operator=(const Vector::Vector3 &v) = default; Vector3& Vector3::operator=(const LinAlg::Vector3 &v) = default;
Vector3& Vector3::operator+=(const Vector::Vector3 &v) { Vector3& Vector3::operator+=(const LinAlg::Vector3 &v) {
*this=*this+v; *this=*this+v;
return *this; return *this;
} }
double Vector3::dot(const Vector::Vector3 &v) const { double Vector3::dot(const LinAlg::Vector3 &v) const {
return x*v.x+y*v.y+z*v.z; return x*v.x+y*v.y+z*v.z;
} }
Vector3 Vector3::cross(const Vector::Vector3& v) const { Vector3 Vector3::cross(const LinAlg::Vector3& v) const {
return {y*v.z-v.y*z,z*v.x-v.z*x,x*v.y-v.x*y}; return {y*v.z-v.y*z,z*v.x-v.z*x,x*v.y-v.x*y};
} }
@ -33,7 +33,7 @@ namespace Vector{
return *this; return *this;
} }
Vector3 &Vector3::operator-=(const Vector::Vector3 &v) { Vector3 &Vector3::operator-=(const LinAlg::Vector3 &v) {
*this=*this-v; *this=*this-v;
return *this; return *this;
} }