ProjGeom 1.0.11
Loading...
Searching...
No Matches
euclid_plane.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <type_traits>
8
9#include "pg_common.hpp" // import cross2, dot1
10#include "proj_plane.hpp" // import pg_point, Involution, tri_func, quad_func, parametrize
11#include "proj_plane_concepts.h"
12
13namespace fun {
14
23 template <ProjectivePlaneCoord2 Line> // // and requires point_p[i]
24 constexpr auto fB(const Line& line_l) -> typename Line::Dual {
25 return {line_l[0], line_l[1], 0};
26 }
27
37 template <ProjectivePlaneCoord2 Line>
38 constexpr auto is_perpendicular(const Line& line_l, const Line& line_m) -> bool {
39 return dot1(line_l, line_m) == 0;
40 }
41
51 template <ProjectivePlaneCoord2 Line>
52 constexpr auto is_parallel(const Line& line_l, const Line& line_m) -> bool {
53 return cross2(line_l, line_m) == 0;
54 }
55
69 template <typename Point, typename Line>
70 requires ProjectivePlaneCoord<Point, Line>
71 constexpr auto altitude(const Point& a, const Line& line_l) -> Line {
72 return a * fB(line_l);
73 }
74
85 template <ProjectivePlaneCoord2 Point>
86 constexpr auto tri_altitude(const Triple<Point>& triangle) {
87 const auto& [a_1, a_2, a_3] = triangle;
88 return std::array{altitude(a_1, a_2 * a_3), altitude(a_2, a_3 * a_1),
89 altitude(a_3, a_1 * a_2)};
90 }
91
122 template <ProjectivePlaneCoord2 Point> constexpr auto orthocenter(const Triple<Point>& triangle)
123 -> Point {
124 const auto& [a_1, a_2, a_3] = triangle;
125 const auto t1 = altitude(a_1, a_2 * a_3);
126 const auto t2 = altitude(a_2, a_1 * a_3);
127 return t1 * t2;
128 }
129
155 template <ProjectivePlaneCoord2 Line> constexpr auto reflect(const Line& line_m) {
156 return Involution{line_m, fB(line_m)};
157 }
158
185 template <ProjectivePlaneCoord2 Point> constexpr auto midpoint(const Point& a, const Point& b)
186 -> Point {
187 return parametrize(b[2], a, a[2], b);
188 }
189
200 template <ProjectivePlaneCoord2 Point>
201 constexpr auto tri_midpoint(const Triple<Point>& triangle) -> Triple<Point> {
202 const auto& [a_1, a_2, a_3] = triangle;
203 return {midpoint(a_1, a_2), midpoint(a_2, a_3), midpoint(a_1, a_3)};
204 }
205
218 template <ProjectivePlaneCoord2 Point>
219 constexpr auto uc_point(const Value_type<Point>& lda1, const Value_type<Point>& mu1) {
220 const auto lda2 = lda1 * lda1;
221 const auto mu2 = mu1 * mu1;
222 return Point{lda2 - mu2, 2 * lda1 * mu1, lda2 + mu2};
223 }
224
237 template <OrderedRing _Q> constexpr auto archimedes(const _Q& a, const _Q& b, const _Q& c) {
238 return 4 * a * b - sq(a + b - c);
239 }
240
257 template <typename _Q> constexpr auto cqq(const _Q& a, const _Q& b, const _Q& c, const _Q& d)
258 -> std::array<_Q, 2> {
259 const auto t1 = 4 * a * b;
260 const auto t2 = 4 * c * d;
261 auto line_m = (t1 + t2) - sq(a + b - c - d);
262 auto point_p = line_m * line_m - 4 * t1 * t2;
263 return {std::move(line_m), std::move(point_p)};
264 }
265
279 template <typename T> constexpr auto Ptolemy(const T& quad) -> bool {
280 const auto& [Q12, Q23, Q34, Q14, Q13, Q24] = quad;
281 using _K = decltype(Q12);
282 return archimedes(Q12 * Q34, Q23 * Q14, Q13 * Q24) == _K(0);
283 }
284
285} // namespace fun
Definition proj_plane.hpp:202
Definition ck_concepts.hpp:11
constexpr auto orthocenter(const std::array< Point, 3 > &triangle) -> Point
Compute the orthocenter of a triangle (Cayley-Klein).
Definition ck_plane.hpp:65
constexpr auto tri_midpoint(const Triple< Point > &triangle) -> Triple< Point >
Compute the midpoints of all three sides of a triangle.
Definition euclid_plane.hpp:201
typename T::value_type Value_type
Value type of a type.
Definition common_concepts.h:23
auto cross2(const std::array< _K, 3 > &v_a, const std::array< _K, 3 > &v_b) -> _K
3rd term of Cross product (xy-plane projection)
Definition pg_common.hpp:57
constexpr auto tri_altitude(const std::array< Point, 3 > &triangle) -> std::array< Line, 3 >
Compute all three altitudes of a triangle (Cayley-Klein).
Definition ck_plane.hpp:87
constexpr auto archimedes(const _Q &a, const _Q &b, const _Q &c)
Archimedes's function.
Definition euclid_plane.hpp:237
constexpr auto reflect(const Line &mirror, const Point &pt_p) -> Point
Reflect a point across a line (Cayley-Klein).
Definition ck_plane.hpp:113
constexpr auto uc_point(const Value_type< Point > &lda1, const Value_type< Point > &mu1)
Compute a point on the unit circle from trigonometric parameters.
Definition euclid_plane.hpp:219
constexpr auto cqq(const _Q &a, const _Q &b, const _Q &c, const _Q &d) -> std::array< _Q, 2 >
Cyclic quadrilateral quadrea theorem.
Definition euclid_plane.hpp:257
constexpr auto fB(const Line &line_l) -> typename Line::Dual
Convert a line to its direction vector in the affine plane.
Definition euclid_plane.hpp:24
std::array< Point, 3 > Triple
Type alias for an array of three points (a triangle)
Definition proj_plane.hpp:58
auto dot1(const std::array< _K, 3 > &v_a, const std::array< _K, 3 > &v_b) -> _K
Dot product of the (x,y)-components of two vectors (affine part)
Definition pg_common.hpp:135
constexpr auto midpoint(const Point &a, const Point &b) -> Point
Compute the midpoint of two points.
Definition euclid_plane.hpp:185
constexpr auto Ptolemy(const T &quad) -> bool
Check Ptolemy's theorem for a cyclic quadrilateral.
Definition euclid_plane.hpp:279
constexpr auto altitude(const Point &pt_p, const Line &ln_m) -> Line
Compute the altitude from a point to a line (Cayley-Klein).
Definition ck_plane.hpp:47
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 is_perpendicular(const Line &l_1, const Line &l_2) -> bool
Check if two lines are perpendicular (Cayley-Klein).
Definition ck_plane.hpp:27
constexpr auto is_parallel(const Line &line_l, const Line &line_m) -> bool
Check if two lines are parallel.
Definition euclid_plane.hpp:52
constexpr auto sq(const T &a)
Square function.
Definition pg_common.hpp:164
C++20 concepts for projective planes with coordinate access and parametrization.