52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
//
|
|
// Created by Иван Ильин on 09.10.2021.
|
|
//
|
|
|
|
#ifndef SHOOTER_VEC3D_H
|
|
#define SHOOTER_VEC3D_H
|
|
|
|
#include <array>
|
|
#include "Point4D.h"
|
|
|
|
class Vec3D {
|
|
private:
|
|
std::array<double, 3> _arr_point{};
|
|
|
|
public:
|
|
Vec3D () = default;
|
|
Vec3D (const Vec3D& vec);
|
|
explicit Vec3D (const Point4D& vec);
|
|
explicit Vec3D (double x, double y = 0.0, double z = 0.0);
|
|
Vec3D& operator=(const Vec3D&) = delete;
|
|
|
|
[[nodiscard]] double x() const { return _arr_point[0]; }
|
|
[[nodiscard]] double y() const { return _arr_point[1]; }
|
|
[[nodiscard]] double z() const { return _arr_point[2]; }
|
|
|
|
[[nodiscard]] Vec3D operator-() const;
|
|
|
|
// Boolean operations
|
|
bool operator==(const Vec3D& vec) const;
|
|
bool operator!=(const Vec3D& vec) const;
|
|
|
|
// Operations with Point4D
|
|
[[nodiscard]] Vec3D operator+(const Vec3D& vec) const;
|
|
[[nodiscard]] Vec3D operator-(const Vec3D& vec) const;
|
|
|
|
[[nodiscard]] double dot(const Vec3D& vec) const; // Returns dot product
|
|
[[nodiscard]] Vec3D cross(const Vec3D& vec) const; // Returns cross product
|
|
|
|
// Operations with numbers
|
|
[[nodiscard]] Vec3D operator*(double number) const;
|
|
[[nodiscard]] Vec3D operator/(double number) const;
|
|
|
|
// Other useful methods
|
|
[[nodiscard]] double sqrAbs() const; // Returns squared vector length
|
|
[[nodiscard]] double abs() const; // Returns vector length
|
|
[[nodiscard]] Vec3D normalized() const; // Returns normalized vector without changing
|
|
[[nodiscard]] Point4D makePoint4D() const;
|
|
};
|
|
|
|
|
|
#endif //SHOOTER_VEC3D_H
|