added matrix and changed namespace from vector to lingalg
This commit is contained in:
parent
e174292201
commit
fff10699e6
2
.idea/.name
generated
2
.idea/.name
generated
@ -1 +1 @@
|
||||
block
|
||||
VolsVecs
|
@ -3,8 +3,8 @@
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::cout << "Hello, world!" << std::endl;
|
||||
Vector::Vector3 vec(1,2,3);
|
||||
Vector::Vector3 vec2(2,1,3);
|
||||
LinAlg::Vector3 vec(1, 2, 3);
|
||||
LinAlg::Vector3 vec2(2, 1, 3);
|
||||
Volumes::Block block(vec,1,1,1);
|
||||
std::cout<<vec<<std::endl;
|
||||
std::cout<<vec.len()<<std::endl;
|
||||
|
@ -10,13 +10,13 @@
|
||||
namespace Volumes{
|
||||
class Block{
|
||||
public:
|
||||
Block(const Vector::Vector3& v1, double x, double y, double z):corners{v1,
|
||||
v1+Vector::Vector3(x,0,0),
|
||||
v1+Vector::Vector3(x,y,0),
|
||||
v1+Vector::Vector3(0,y,z),v1,
|
||||
v1+Vector::Vector3(x,y,z),
|
||||
v1+Vector::Vector3(x,0,z),
|
||||
v1+Vector::Vector3(0,0,z)}{};
|
||||
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(x, y, z),
|
||||
v1 + LinAlg::Vector3(x, 0, z),
|
||||
v1 + LinAlg::Vector3(0, 0, z)}{};
|
||||
virtual ~Block() = default;
|
||||
|
||||
double getVolume();
|
||||
@ -24,7 +24,7 @@ namespace Volumes{
|
||||
friend std::ostream& operator<<(std::ostream& os, const Block& v){
|
||||
os<<"[";
|
||||
short count=0;
|
||||
for(Vector::Vector3 corner:v.corners){
|
||||
for(LinAlg::Vector3 corner:v.corners){
|
||||
count++;
|
||||
os<<corner;
|
||||
if(count<8) {
|
||||
@ -36,7 +36,7 @@ namespace Volumes{
|
||||
}
|
||||
|
||||
private:
|
||||
Vector::Vector3 corners[8];
|
||||
LinAlg::Vector3 corners[8];
|
||||
};
|
||||
}
|
||||
|
||||
|
19
include/LinAlg/matrix3.h
Normal file
19
include/LinAlg/matrix3.h
Normal 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
|
@ -8,7 +8,7 @@
|
||||
#include "iostream"
|
||||
#include <cmath>
|
||||
|
||||
namespace Vector{
|
||||
namespace LinAlg{
|
||||
class Vector3{
|
||||
public:
|
||||
Vector3(double x,double y, double z):x(x),y(y),z(z){};
|
@ -5,9 +5,9 @@
|
||||
|
||||
namespace Volumes{
|
||||
double Block::getVolume() {
|
||||
Vector::Vector3 x=corners[1]-corners[0];
|
||||
Vector::Vector3 y=corners[3]-corners[0];
|
||||
Vector::Vector3 z=corners[7]-corners[0];
|
||||
LinAlg::Vector3 x= corners[1] - corners[0];
|
||||
LinAlg::Vector3 y= corners[3] - corners[0];
|
||||
LinAlg::Vector3 z= corners[7] - corners[0];
|
||||
return x.len()*y.len()*z.len();
|
||||
}
|
||||
}
|
10
src/matrix3.cpp
Normal file
10
src/matrix3.cpp
Normal 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;
|
||||
}
|
||||
}
|
@ -1,22 +1,22 @@
|
||||
#include "Vector/vector3.h"
|
||||
|
||||
namespace Vector{
|
||||
Vector3 Vector3::operator+(const Vector::Vector3 &v) const {
|
||||
namespace LinAlg{
|
||||
Vector3 Vector3::operator+(const LinAlg::Vector3 &v) const {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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};
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ namespace Vector{
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3 &Vector3::operator-=(const Vector::Vector3 &v) {
|
||||
Vector3 &Vector3::operator-=(const LinAlg::Vector3 &v) {
|
||||
*this=*this-v;
|
||||
return *this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user