ProjGeom 1.0.11
Loading...
Searching...
No Matches
pg_object.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <array>
8#include <cstdint>
9
10// #include "common_concepts.h"
11#include "pg_plane.hpp"
12
23constexpr auto dot(const std::array<int64_t, 3>& pt_a, const std::array<int64_t, 3>& pt_b)
24 -> int64_t {
25 return pt_a[0] * pt_b[0] + pt_a[1] * pt_b[1] + pt_a[2] * pt_b[2];
26}
27
38constexpr auto cross(const std::array<int64_t, 3>& pt_a, const std::array<int64_t, 3>& pt_b)
39 -> std::array<int64_t, 3> {
40 return {
41 pt_a[1] * pt_b[2] - pt_a[2] * pt_b[1],
42 pt_a[2] * pt_b[0] - pt_a[0] * pt_b[2],
43 pt_a[0] * pt_b[1] - pt_a[1] * pt_b[0],
44 };
45}
46
59constexpr auto plckr(const int64_t& lambda, const std::array<int64_t, 3>& pt_p, const int64_t& mu,
60 const std::array<int64_t, 3>& pt_q) -> std::array<int64_t, 3> {
61 return {
62 lambda * pt_p[0] + mu * pt_q[0],
63 lambda * pt_p[1] + mu * pt_q[1],
64 lambda * pt_p[2] + mu * pt_q[2],
65 };
66}
67
68namespace fun {
69
79 template <Ring _K, typename Self, typename DualType> struct pg_object {
80 using Dual = DualType;
81 using value_type = _K;
82
83 std::array<_K, 3> coord;
84
85 constexpr explicit pg_object(std::array<_K, 3> coord) : coord{std::move(coord)} {}
86
87 constexpr pg_object(const _K& x, const _K& y, const _K& z) : coord{{x, y, z}} {}
88
89 friend constexpr auto operator==(const Self& lhs, const Self& rhs) -> bool {
90 return &lhs == &rhs
91 || (lhs.coord[1] * rhs.coord[2] == lhs.coord[2] * rhs.coord[1]
92 && lhs.coord[2] * rhs.coord[0] == lhs.coord[0] * rhs.coord[2]
93 && lhs.coord[0] * rhs.coord[1] == lhs.coord[1] * rhs.coord[0]);
94 }
95
96 friend constexpr auto operator!=(const Self& lhs, const Self& rhs) -> bool {
97 return !(lhs == rhs);
98 }
99
100 friend constexpr auto operator*(const Self& lhs, const Self& rhs) -> DualType {
101 return DualType{::cross(lhs.coord, rhs.coord)};
102 }
103
104 constexpr auto aux() const -> DualType { return DualType{this->coord}; }
105
106 constexpr auto dot(const DualType& other) const -> _K {
107 return this->coord[0] * other.coord[0] + this->coord[1] * other.coord[1]
108 + this->coord[2] * other.coord[2];
109 }
110
111 constexpr auto incident(const DualType& other) const -> bool {
112 return this->dot(other) == _K(0);
113 }
114
115 static constexpr auto parametrize(const _K& lambda_val, const Self& pt_p, const _K& mu_val,
116 const Self& pt_q) -> Self {
117 return Self{::plckr(lambda_val, pt_p.coord, mu_val, pt_q.coord)};
118 }
119 };
120
121} // namespace fun
122
129template <typename Point, typename Line> struct PgObject {
130 using Dual = Line;
131
132 std::array<int64_t, 3> coord;
133
139 constexpr explicit PgObject(std::array<int64_t, 3> coord) : coord{std::move(coord)} {}
140
149 friend constexpr auto operator==(const Point& lhs, const Point& rhs) -> bool {
150 return &lhs == &rhs ? true
151 : lhs.coord[1] * rhs.coord[2] == lhs.coord[2] * rhs.coord[1]
152 && lhs.coord[2] * rhs.coord[0] == lhs.coord[0] * rhs.coord[2]
153 && lhs.coord[0] * rhs.coord[1] == lhs.coord[1] * rhs.coord[0];
154 }
155
164 friend constexpr auto operator!=(const Point& lhs, const Point& rhs) -> bool {
165 return !(lhs == rhs);
166 }
167
173 constexpr auto aux() const -> Line { return Line{this->coord}; }
174
184 constexpr auto dot(const Line& other) const -> int64_t {
185 return ::dot(this->coord, other.coord);
186 }
187
200 static constexpr auto parametrize(const int64_t& lambda_val, const Point& pt_p,
201 const int64_t& mu_val, const Point& pt_q) -> Point {
202 return Point{::plckr(lambda_val, pt_p.coord, mu_val, pt_q.coord)};
203 }
204
212 constexpr auto incident(const Line& other) const -> bool { return this->dot(other) == 0; }
213
223 constexpr auto meet(const Point& rhs) const -> Line {
224 return Line{::cross(this->coord, rhs.coord)};
225 }
226};
227
228class PgPoint;
229class PgLine;
230
235class PgPoint : public PgObject<PgPoint, PgLine> {
236 public:
242 constexpr explicit PgPoint(std::array<int64_t, 3> coord)
243 : PgObject<PgPoint, PgLine>{std::move(coord)} {}
244};
245
250class PgLine : public PgObject<PgLine, PgPoint> {
251 public:
257 constexpr explicit PgLine(std::array<int64_t, 3> coord)
258 : PgObject<PgLine, PgPoint>{std::move(coord)} {}
259};
PG Line.
Definition pg_object.hpp:250
constexpr PgLine(std::array< int64_t, 3 > coord)
Construct a new Pg Line object.
Definition pg_object.hpp:257
PG Point.
Definition pg_object.hpp:235
constexpr PgPoint(std::array< int64_t, 3 > coord)
Construct a new Pg Point object.
Definition pg_object.hpp:242
Definition ck_concepts.hpp:11
auto cross(const Point &v_a, const Point &v_b) -> std::array< Value_type< Point >, 3 >
Cross product in homogeneous 3D coordinates.
Definition pg_common.hpp:79
constexpr auto cross(const std::array< int64_t, 3 > &pt_a, const std::array< int64_t, 3 > &pt_b) -> std::array< int64_t, 3 >
Cross product of two homogeneous 3-vectors.
Definition pg_object.hpp:38
constexpr auto plckr(const int64_t &lambda, const std::array< int64_t, 3 > &pt_p, const int64_t &mu, const std::array< int64_t, 3 > &pt_q) -> std::array< int64_t, 3 >
Homogeneous parametrization of point or line.
Definition pg_object.hpp:59
constexpr auto dot(const std::array< int64_t, 3 > &pt_a, const std::array< int64_t, 3 > &pt_b) -> int64_t
Dot product of two homogeneous 3-vectors.
Definition pg_object.hpp:23
Projective plane axioms and geometric checks (coincidence, Pappus, Desargues).
Projective Point/Line (int64_t specialization)
Definition pg_object.hpp:129
constexpr auto incident(const Line &other) const -> bool
Check incidence with the dual object.
Definition pg_object.hpp:212
constexpr auto meet(const Point &rhs) const -> Line
Meet (intersection) with another point to form a line.
Definition pg_object.hpp:223
constexpr auto dot(const Line &other) const -> int64_t
Dot product with the dual object.
Definition pg_object.hpp:184
constexpr auto aux() const -> Line
Return the dual object (auxiliary line/point).
Definition pg_object.hpp:173
std::array< int64_t, 3 > coord
Definition pg_object.hpp:132
static constexpr auto parametrize(const int64_t &lambda_val, const Point &pt_p, const int64_t &mu_val, const Point &pt_q) -> Point
Homogeneous parametrization of point or line.
Definition pg_object.hpp:200
constexpr PgObject(std::array< int64_t, 3 > coord)
Construct a new Pg Object object.
Definition pg_object.hpp:139
friend constexpr auto operator==(const Point &lhs, const Point &rhs) -> bool
Equal to.
Definition pg_object.hpp:149
friend constexpr auto operator!=(const Point &lhs, const Point &rhs) -> bool
Not equal to.
Definition pg_object.hpp:164
Line Dual
Definition pg_object.hpp:130
Generic projective geometry object (value-type templated)
Definition pg_object.hpp:79
friend constexpr auto operator*(const Self &lhs, const Self &rhs) -> DualType
Definition pg_object.hpp:100
constexpr auto dot(const DualType &other) const -> _K
Definition pg_object.hpp:106
static constexpr auto parametrize(const _K &lambda_val, const Self &pt_p, const _K &mu_val, const Self &pt_q) -> Self
Definition pg_object.hpp:115
constexpr pg_object(const _K &x, const _K &y, const _K &z)
Definition pg_object.hpp:87
constexpr pg_object(std::array< _K, 3 > coord)
Definition pg_object.hpp:85
DualType Dual
Definition pg_object.hpp:80
constexpr auto aux() const -> DualType
Definition pg_object.hpp:104
friend constexpr auto operator==(const Self &lhs, const Self &rhs) -> bool
Definition pg_object.hpp:89
constexpr auto incident(const DualType &other) const -> bool
Definition pg_object.hpp:111
_K value_type
Definition pg_object.hpp:81
std::array< _K, 3 > coord
Definition pg_object.hpp:83
friend constexpr auto operator!=(const Self &lhs, const Self &rhs) -> bool
Definition pg_object.hpp:96