Teaching geometry to C++
Guy Davidson Meeting C++ 15/11/2019 @hatcat01
1
Teaching geometry to C++ Guy Davidson Meeting C++ 15/11/2019 - - PowerPoint PPT Presentation
Teaching geometry to C++ Guy Davidson Meeting C++ 15/11/2019 @hatcat01 1 What to expect... 0. A brief history of geometry [4 - 22] 1. Linear algebra and geometry [24 - 57] 2. Lines and curves [59 - 82] 3. Polygons, regular and irregular [84
Guy Davidson Meeting C++ 15/11/2019 @hatcat01
1
@hatcat01
3
@hatcat01
4
“The branch of mathematics concerned with questions of shape, size, relative position of figures and the properties
@hatcat01
5
“The branch of mathematics concerned with questions of shape, size, relative position of figures and the properties
@hatcat01
6
“The branch of mathematics concerned with questions of shape, size, relative position of figures and the properties
@hatcat01
7
@hatcat01
8
@hatcat01
9
@hatcat01
10
@hatcat01
11
René Descartes
@hatcat01
12
Lots
@hatcat01
13
x Lots
y Lots
@hatcat01
14
@hatcat01
15
x,y in R {y - 2x - 3 = 0}
x y
@hatcat01
16
y = 2x + 3
x y
@hatcat01
17
x y
y = -x2
@hatcat01
18
x y
x,y in R {x2 + y2 - 3 = 0}
@hatcat01
19
x y
x,y in R, t in R, 0 <= t <= 2pi {x = 3 * sin(t), y = 3 * cos(t)}
Other geometries
20
Other geometries: Differential geometry
21
Other geometries: Differential geometry Algebraic geometry
22
Other geometries: Differential geometry Algebraic geometry Cartesian geometry
23
@hatcat01
24
@hatcat01
25
a1x1 + a2x2 + … + anxn = b
@hatcat01
26
a1x1 + a2x2 + … + anxn = b a1x1 + a2x2 = b
@hatcat01
27
a1x1 + a2x2 + … + anxn = b a1x1 + a2x2 = b ax + by = c
@hatcat01
28
a1x1 + a2x2 + … + anxn = b a1x1 + a2x2 = b ax + by = c by = -ax + c
@hatcat01
29
a1x1 + a2x2 + … + anxn = b a1x1 + a2x2 = b ax + by = c by = -ax + c y = mx + c
@hatcat01
30
(x, y)
@hatcat01
31
(x, y) Translate (x, y) + (a, b) = (x+a, y+b)
Scale (x, y) * 2 = (2x, 2y) (x, y) * (2 0) = (2x, 2y) (0 2)
@hatcat01
32
Shear (x, y) * (1 2) = (x, 2x + y) (0 1)
@hatcat01
33
Reflect (x, y) * (1 0) = (x, -y) (0 -1)
@hatcat01
34
Rotate (x, y) * (cos a -sin a) (sin a cos a) = (x*cos a + y*sin a,
@hatcat01
35
@hatcat01
36
Boost.Geometry
@hatcat01
37
Boost.Geometry Barend Gehrels
@hatcat01
38
Boost.Geometry Barend Gehrels Geometry classes
@hatcat01
39
Boost.Geometry Barend Gehrels Geometry classes Dimension agnostic
@hatcat01
40
Boost.Geometry Barend Gehrels Geometry classes Dimension agnostic Distance
@hatcat01
41
Boost.Geometry Barend Gehrels Geometry classes Dimension agnostic Distance Coordinate-system agnostic
@hatcat01
42
@hatcat01
43
x,y in R {-3 <= x <= 5} {y = x/2 + 5/2}
x y
struct line { float gradient; float y_intercept; };
44
@hatcat01
struct line { float gradient; float y_intercept; }; struct line_segment { point p1; point p2; };
45
@hatcat01
Q
46
@hatcat01
Q 3244.7482
47
@hatcat01
48
@hatcat01
49
@hatcat01
50
@hatcat01
class line { std::vector<point> points; };
51
@hatcat01
class line { float gradient; float intercept; };
52
@hatcat01
class line { float gradient; float intercept; point p1; point p2; };
53
@hatcat01
class line { float gradient; float intercept; point p_begin; point p_end; };
54
@hatcat01
Curves
55
@hatcat01
@hatcat01
56
y = x2
x y
57
@hatcat01
class curve { point p1; point p2; point c1; point c2; };
58
@hatcat01
class curve { point p1; point p2; point c1; point c2; }; Quadratic Bézier curve
59
@hatcat01
60
@hatcat01
61
@hatcat01
62
@hatcat01
63
@hatcat01
64
@hatcat01
65
@hatcat01
66
@hatcat01
class curve { point p1; point p2; point control_point; };
67
@hatcat01
@hatcat01
68
@hatcat01
69
class triangle { point p1; point p2; point p3; };
70
@hatcat01
@hatcat01
71
class square { point p1; point p2; point p3; point p4; };
72
@hatcat01
class polygon { std::vector<point>; };
73
@hatcat01
class regular_polygon { point centre; point p; size_t vertex_count; float orientation; };
74
@hatcat01
75
@hatcat01
x Lots
y Lots
76
@hatcat01
class circle { point centre; float radius; };
77
@hatcat01
78
@hatcat01
class ellipse { point focus_1; point focus_2; float radius; bool major; };
79
@hatcat01
80
@hatcat01
81
@hatcat01
82
@hatcat01
class stadium { point focus_1; point focus_2; float radius; };
83
@hatcat01
84
@hatcat01
class polycurve { std::vector<std::curve> segments; };
85
@hatcat01
class polycurve { std::vector<std::pair<std::point>> segments; std::optional<point> end_point; };
86
@hatcat01
@hatcat01
87
Intersection
@hatcat01
88
Intersection y = x - 1 y = 2x - 4
@hatcat01
89
Intersection y = x - 1 y = 2x - 4 0 = x - 3 x = 3
@hatcat01
90
Intersection y = x2 y = x + 3.9
@hatcat01
91
Intersection y = x2 y = x + 3.9 0 = x2 - x - 3.9 x = 0.5 ± √(4.15)
@hatcat01
92
Intersection y = x - 2.3 y = x/3
@hatcat01
93
Intersection y = x - 2.3 y = x/3 0 = 2x/3 - 2.3 x = 3.45
@hatcat01
94
@hatcat01
95
Round of applause for the brave volunteer
@hatcat01
96
Round of applause for the brave volunteer Swords
@hatcat01
97
Round of applause for the brave volunteer Swords Fast and thin
@hatcat01
98
Round of applause for the brave volunteer Swords Fast and thin bool intersects(line a, line b);
@hatcat01
99
Round of applause for the brave volunteer Swords Fast and thin bool intersects(line a, line b); FLT_MIN vs FLT_EPSILON
@hatcat01
100
bool intersects(line a, line b, float epsilon);
@hatcat01
101
@hatcat01
102
std::math
103
@hatcat01
std::math using float_2 = std::math::vector<fs_vector_engine<float, 2>>; using float_22 = std::math::matrix<fs_matrix_engine<float, 2, 2>>;
104
@hatcat01
std::math using float_2 = std::math::vector<fs_vector_engine<float, 2>>; using float_22 = std::math::matrix<fs_matrix_engine<float, 2, 2>>; Implementer specialisation
105
@hatcat01
std::math::path
106
@hatcat01
std::math::path 3 (or 4?) control points
107
@hatcat01
std::math::path 3 (or 4?) control points std::math::polyline
108
@hatcat01
std::math::path 3 (or 4?) control points std::math::polyline std::math::polycurve
109
@hatcat01
template <int N, typename coordinate_system> class regular_polygon;
110
@hatcat01
template <int N, typename coordinate_system> class regular_polygon; template <typename coordinate_system> using triangle = regular_polygon<3, coordinate_system>;
111
@hatcat01
template <int N, typename coordinate_system> class regular_polygon; template <typename coordinate_system> using triangle = regular_polygon<3, coordinate_system>; class circle;
112
@hatcat01
template <int N, typename coordinate_system> class regular_polygon; template <typename coordinate_system> using triangle = regular_polygon<3, coordinate_system>; class circle; class ellipse;
113
@hatcat01
template <int N, typename coordinate_system> class regular_polygon; template <typename coordinate_system> using triangle = regular_polygon<3, coordinate_system>; class circle; class ellipse; class stadium; (?)
114
@hatcat01
template <int N, typename coordinate_system> class regular_polygon; template <typename coordinate_system> using triangle = regular_polygon<3, coordinate_system>; class circle; class ellipse; class stadium; (?) class patch;
115
@hatcat01
intersect()
116
@hatcat01
intersect() distance()
117
@hatcat01
intersect() distance() length()
118
@hatcat01
contains()
119
@hatcat01
contains() area()
120
@hatcat01
contains() area() perimeter()
121
@hatcat01
contains() area() perimeter() centroid()
122
@hatcat01
contains() area() perimeter() centroid() envelope()
123
@hatcat01
Ask me two questions.
@hatcat01
124
This was built using show.cpp which you can find at github.com/hatcat/show.cpp along with this presentation. show.cpp makes use of the C++ Standard Graphics proposal which you can find at github.com/cpp-io2d. Thanks to the io2d team for keeping things going. Thanks also to Hana Dusíková for prompting me to create a piece of open source C++ presentation software. Your move...
125
@hatcat01