Volumes/include/LinAlg/vector3.h

66 lines
1.3 KiB
C
Raw Normal View History

2024-07-07 20:42:39 +02:00
//
// Created by nb on 07.07.24.
//
#ifndef VECTOR_VECTOR3_H
#define VECTOR_VECTOR3_H
#include "iostream"
#include <cmath>
2024-08-18 21:57:24 +02:00
namespace LinAlg {
class Vector3 {
2024-07-07 20:42:39 +02:00
public:
2024-08-18 21:57:24 +02:00
Vector3(double x, double y, double z) : x(x), y(y), z(z) {};
Vector3() : Vector3(0, 0, 0) {};
2024-07-07 20:42:39 +02:00
virtual ~Vector3() = default;
2024-08-18 21:57:24 +02:00
Vector3 operator+(const Vector3 &v) const;
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
Vector3 operator-(const Vector3 &v) const {
Vector3 tmp = v * -1;
return *this + tmp;
2024-07-07 20:42:39 +02:00
};
Vector3 operator*(double s) const;
2024-08-18 21:57:24 +02:00
Vector3 operator/(double s) const {
return *this * (1 / s);
2024-07-07 20:42:39 +02:00
};
2024-08-18 21:57:24 +02:00
Vector3 &operator*=(double s);
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
Vector3 &operator/=(double s) {
return *this *= (1 / s);
2024-07-07 20:42:39 +02:00
};
2024-08-18 21:57:24 +02:00
Vector3 &operator+=(const Vector3 &v);
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
Vector3 &operator-=(const Vector3 &v);
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
Vector3 &operator=(const Vector3 &v);
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
Vector3 &norm();
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
[[nodiscard]] double dot(const Vector3 &v) const;
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
[[nodiscard]] double len() const;
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
[[nodiscard]] Vector3 cross(const Vector3 &v) const;
2024-07-07 20:42:39 +02:00
2024-08-18 21:57:24 +02:00
friend std::ostream &operator<<(std::ostream &os, const Vector3 &v) {
os << "{" << v.x << ", " << v.y << ", " << v.z << "}";
2024-07-07 20:42:39 +02:00
return os;
}
private:
2024-08-18 21:57:24 +02:00
double x, y, z;
2024-07-07 20:42:39 +02:00
};
}
#endif //VECTOR_VECTOR3_H