2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 19.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_PLANE_H
|
|
|
|
#define ENGINE_PLANE_H
|
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
#include "Point4D.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
#include "Triangle.h"
|
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class Plane final {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
|
|
|
// You can define plane by defining the points in 3D space
|
2021-09-19 11:25:10 +03:00
|
|
|
Triangle _triangle;
|
2021-09-13 15:53:43 +03:00
|
|
|
// Or by defining normal vector and one val laying on the plane
|
2021-10-12 17:12:47 +03:00
|
|
|
Vec3D _n = Vec3D{0, 0, 1};
|
|
|
|
Vec3D _p{};
|
2021-09-13 15:53:43 +03:00
|
|
|
public:
|
2021-09-19 11:25:10 +03:00
|
|
|
// A plain with normal vector '_n' and val '_p' lays on the plane
|
2021-09-13 15:53:43 +03:00
|
|
|
Plane() = default;
|
2021-10-12 17:12:47 +03:00
|
|
|
Plane(const Vec3D& N, const Vec3D& P);
|
|
|
|
Plane(const Plane& plane) = default;
|
2021-09-13 15:53:43 +03:00
|
|
|
explicit Plane(const Triangle& tri);
|
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
[[nodiscard]] double distance(const Vec3D& point4D) const;
|
2021-09-19 11:25:10 +03:00
|
|
|
// Point4D in space where line ('start' to 'end') intersects plain with normal vector '_n' and val '_p' lays on the plane
|
2021-10-12 17:12:47 +03:00
|
|
|
[[nodiscard]] std::pair<Vec3D, double> intersection(const Vec3D& start, const Vec3D& end) const;
|
|
|
|
[[nodiscard]] std::vector<Triangle> clip(const Triangle& tri) const;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
[[nodiscard]] Vec3D N() const { return _n; }
|
|
|
|
[[nodiscard]] Vec3D P() const { return _p; }
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_PLANE_H
|