ProjGeom 1.0.11
Loading...
Searching...
No Matches
proj_plane.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cassert>
5#include <tuple>
6
8
17namespace fun {
18
33 template <typename Point, typename Line>
34 requires ProjectivePlane<Point, Line>
35 constexpr auto incident(const Point& pt_p, const Line& ln_l) -> bool {
36 return pt_p.dot(ln_l) == Value_type<Point>(0);
37 }
38
47 template <typename Line, typename... Args>
48 requires(ProjectivePlanePrim<Line, Args> && ...)
49 constexpr auto coincident(const Line& ln_l, const Args&... pt_r) -> bool {
50 return (incident(pt_r, ln_l) && ...);
51 }
52
58 template <typename Point> using Triple = std::array<Point, 3>;
59
71 template <ProjectivePlanePrim2 Point> constexpr auto tri_dual(const Triple<Point>& triangle)
72
73 {
74 const auto& [a_1, a_2, a_3] = triangle;
75 assert(!coincident(a_2 * a_3, a_1));
76 return std::array{a_2 * a_3, a_1 * a_3, a_1 * a_2};
77 }
78
88 template <ProjectivePlanePrim2 Point, typename Fn>
89 constexpr auto tri_func(Fn&& func, const Triple<Point>& triangle)
90
91 {
92 const auto& [a_1, a_2, a_3] = triangle;
93 return std::array{func(a_2, a_3), func(a_1, a_3), func(a_1, a_2)};
94 }
95
104 template <ProjectivePlanePrim2 Point>
105 constexpr auto persp(const Triple<Point>& tri1, const Triple<Point>& tri2) -> bool {
106 const auto& [A, B, C] = tri1;
107 const auto& [D, E, F] = tri2;
108 const auto O = (A * D) * (B * E);
109 return incident(O, C * F);
110 }
111
142 template <ProjectivePlane2 Point>
143 constexpr auto harm_conj(const Point& A, const Point& B, const Point& C) -> Point {
144 assert(incident(A * B, C));
145 const auto lC = C * (A * B).aux();
146 return parametrize(B.dot(lC), A, A.dot(lC), B);
147 }
148
166 template <ProjectivePlaneGeneric2 _Point>
167 constexpr auto harm_conj(const _Point& A, const _Point& B, const _Point& C) -> _Point {
168 assert(incident(A * B, C));
169 const auto AB = A * B;
170 const auto P = AB.aux();
171 const auto R = P.aux2(C);
172 const auto S = (A * R) * (B * P);
173 const auto Q = (B * R) * (A * P);
174 return (Q * S) * AB;
175 }
176
188 template <ProjectivePlane2 Point>
189 constexpr auto is_harmonic(const Point& A, const Point& B, const Point& C, const Point& D)
190 -> bool {
191 return harm_conj(A, B, C) == D;
192 }
193
200 template <typename Point, typename Line>
201 requires ProjectivePlane<Point, Line>
203 using K = Value_type<Point>;
204
205 private:
206 Line _m;
207 Point _o;
208 K _c;
209
210 public:
217 constexpr Involution(Line ln_m, Point o) // input mirror and center
218 : _m{std::move(ln_m)}, _o{std::move(o)}, _c{_m.dot(_o)} {}
219
230 constexpr auto operator()(const Point& pt_p) const -> Point {
231 return parametrize(this->_c, pt_p, K(-2 * pt_p.dot(this->_m)), this->_o);
232 }
233
244 constexpr auto operator()(const Line& ln_l) const -> Line {
245 return parametrize(this->_c, ln_l, K(-2 * ln_l.dot(this->_o)), this->_m);
246 }
247 };
248
256 template <typename Point, typename Line>
257 requires ProjectivePlaneGeneric<Point, Line>
259 private:
260 Line _m;
261 Point _o;
262
263 public:
270 constexpr involution_generic(Line ln_m,
271 Point o) // input mirror and center
272 : _m{std::move(ln_m)}, _o{std::move(o)} {}
273
281 constexpr auto operator()(const Point& pt_p) const -> Point {
282 auto po = pt_p * this->_o;
283 auto B = po * this->_m;
284 return harm_conj(this->_o, B, pt_p);
285 }
286 };
287
296 template <ProjectivePlanePrim2 Point>
297 void check_pappus(const Triple<Point>& coline1, const Triple<Point>& coline2)
298
299 {
300 const auto& [A, B, C] = coline1;
301 const auto& [D, E, F] = coline2;
302
303 const auto G = (A * E) * (B * D);
304 const auto H = (A * F) * (C * D);
305 const auto I = (B * F) * (C * E);
306 assert(coincident(G, H, I));
307 }
308
318 template <ProjectivePlanePrim2 Point>
319 void check_desargue(const Triple<Point>& tri1, const Triple<Point>& tri2) {
320 const auto trid1 = tri_dual(tri1);
321 const auto trid2 = tri_dual(tri2);
322 const auto bool1 = persp(tri1, tri2);
323 const auto bool2 = persp(trid1, trid2);
324 assert((bool1 && bool2) || (!bool1 && !bool2));
325 }
326
327} // namespace fun
Definition proj_plane.hpp:202
constexpr auto operator()(const Point &pt_p) const -> Point
Apply the involution to a point.
Definition proj_plane.hpp:230
constexpr Involution(Line ln_m, Point o)
Construct a new Involution object.
Definition proj_plane.hpp:217
constexpr auto operator()(const Line &ln_l) const -> Line
Apply the involution to a line.
Definition proj_plane.hpp:244
Generic involution class for projective planes.
Definition proj_plane.hpp:258
constexpr auto operator()(const Point &pt_p) const -> Point
Apply the involution to a point.
Definition proj_plane.hpp:281
constexpr involution_generic(Line ln_m, Point o)
Construct a new generic involution object.
Definition proj_plane.hpp:270
Definition ck_concepts.hpp:11
constexpr auto check_pappus(const std::array< Point, 3 > &coline1, const std::array< Point, 3 > &coline2) -> bool
Check Pappus Theorem.
Definition pg_plane.hpp:68
constexpr auto incident(const Point &pt_p, const Line &ln_l) -> bool
The code snippet is defining a function named incident that checks if a point pt_p is incident to a l...
Definition proj_plane.hpp:35
constexpr auto persp(const std::array< Point, 3 > &tri1, const std::array< Point, 3 > &tri2) -> bool
return whether two triangles are perspective
Definition pg_plane.hpp:112
typename T::value_type Value_type
Value type of a type.
Definition common_concepts.h:23
constexpr auto R(const Point &A, const Point &B, const Point &C, const Point &D)
Compute the cross ratio of four collinear points.
Definition proj_plane_measure.hpp:78
std::array< Point, 3 > Triple
Type alias for an array of three points (a triangle)
Definition proj_plane.hpp:58
constexpr auto tri_dual(const std::array< Point, 3 > &triangle) -> std::array< Line, 3 >
Dual of triangle.
Definition pg_plane.hpp:93
constexpr auto harm_conj(const Point &pt_a, const Point &pt_b, const Point &pt_c) -> Point
Harmonic conjugate.
Definition pg_plane.hpp:184
constexpr auto is_harmonic(const Point &A, const Point &B, const Point &C, const Point &D) -> bool
Check if four points form a harmonic range.
Definition proj_plane.hpp:189
constexpr auto coincident(const Point &pt_p, const Point &pt_q, const Point &pt_r) -> bool
Coincident.
Definition pg_plane.hpp:51
constexpr auto parametrize(const Value &lambda_val, const Point &pt_p, const Value &mu_val, const Point &pt_q) -> Point
Homogeneous parametrization of point or line (free function)
Definition pg_common.hpp:185
constexpr auto check_desargue(const std::array< Point, 3 > &tri1, const std::array< Point, 3 > &tri2) -> bool
Check Desargue's Theorem.
Definition pg_plane.hpp:133
constexpr auto tri_func(Fn &&func, const Triple< Point > &triangle)
Apply a binary function to all pairs of triangle vertices.
Definition proj_plane.hpp:89
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
C++20 concepts for projective planes with coordinate access and parametrization.