Teaching geometry to C++ Guy Davidson Meeting C++ 15/11/2019 - - PowerPoint PPT Presentation

teaching geometry to c
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Teaching geometry to C++

Guy Davidson Meeting C++ 15/11/2019 @hatcat01

1

slide-2
SLIDE 2
slide-3
SLIDE 3

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 - 101]
  • 4. Intersection and precision [119 - 132]
  • 5. Summary of classes and functions [134 - 154]

@hatcat01

3

slide-4
SLIDE 4

What to expect...

  • 0. A brief history of geometry
  • 1. Linear algebra and geometry
  • 2. Lines and curves
  • 3. Polygons, regular and irregular
  • 4. Intersection and precision
  • 5. Summary of classes and functions

@hatcat01

4

slide-5
SLIDE 5

A Brief History Of Geometry

“The branch of mathematics concerned with questions of shape, size, relative position of figures and the properties

  • f space.”

@hatcat01

5

slide-6
SLIDE 6

A Brief History Of Geometry

“The branch of mathematics concerned with questions of shape, size, relative position of figures and the properties

  • f space.”

@hatcat01

6

slide-7
SLIDE 7

A Brief History Of Geometry

“The branch of mathematics concerned with questions of shape, size, relative position of figures and the properties

  • f space.”

@hatcat01

7

slide-8
SLIDE 8

A Brief History Of Geometry

@hatcat01

8

slide-9
SLIDE 9

A Brief History Of Geometry

@hatcat01

9

slide-10
SLIDE 10

A Brief History Of Geometry

@hatcat01

10

slide-11
SLIDE 11

A Brief History Of Geometry

@hatcat01

11

René Descartes

  • b. 31st March 1596
  • d. 11th February 1650
slide-12
SLIDE 12

A Brief History Of Geometry

@hatcat01

12

Lots

  • Lots
slide-13
SLIDE 13

A Brief History Of Geometry

@hatcat01

13

x Lots

  • Lots
  • Lots

y Lots

slide-14
SLIDE 14

A Brief History Of Geometry

@hatcat01

14

slide-15
SLIDE 15

A Brief History Of Geometry

@hatcat01

15

x,y in R {y - 2x - 3 = 0}

x y

slide-16
SLIDE 16

A Brief History Of Geometry

@hatcat01

16

y = 2x + 3

x y

slide-17
SLIDE 17

A Brief History Of Geometry

@hatcat01

17

x y

y = -x2

slide-18
SLIDE 18

A Brief History Of Geometry

@hatcat01

18

x y

x,y in R {x2 + y2 - 3 = 0}

slide-19
SLIDE 19

A Brief History Of Geometry

@hatcat01

19

x y

x,y in R, t in R, 0 <= t <= 2pi {x = 3 * sin(t), y = 3 * cos(t)}

slide-20
SLIDE 20

A Brief History Of Geometry

Other geometries

20

slide-21
SLIDE 21

A Brief History Of Geometry

Other geometries: Differential geometry

21

slide-22
SLIDE 22

A Brief History Of Geometry

Other geometries: Differential geometry Algebraic geometry

22

slide-23
SLIDE 23

A Brief History Of Geometry

Other geometries: Differential geometry Algebraic geometry Cartesian geometry

23

slide-24
SLIDE 24

What to expect...

  • 0. A brief history of geometry
  • 1. Linear algebra and geometry
  • 2. Lines and curves
  • 3. Polygons, regular and irregular
  • 4. Intersection and precision
  • 5. Summary of classes and functions

@hatcat01

24

slide-25
SLIDE 25

Linear Algebra And Geometry

@hatcat01

25

a1x1 + a2x2 + … + anxn = b

slide-26
SLIDE 26

Linear Algebra And Geometry

@hatcat01

26

a1x1 + a2x2 + … + anxn = b a1x1 + a2x2 = b

slide-27
SLIDE 27

Linear Algebra And Geometry

@hatcat01

27

a1x1 + a2x2 + … + anxn = b a1x1 + a2x2 = b ax + by = c

slide-28
SLIDE 28

Linear Algebra And Geometry

@hatcat01

28

a1x1 + a2x2 + … + anxn = b a1x1 + a2x2 = b ax + by = c by = -ax + c

slide-29
SLIDE 29

Linear Algebra And Geometry

@hatcat01

29

a1x1 + a2x2 + … + anxn = b a1x1 + a2x2 = b ax + by = c by = -ax + c y = mx + c

slide-30
SLIDE 30

Linear Algebra And Geometry

@hatcat01

30

(x, y)

slide-31
SLIDE 31

Linear Algebra And Geometry

@hatcat01

31

(x, y) Translate (x, y) + (a, b) = (x+a, y+b)

slide-32
SLIDE 32

Scale (x, y) * 2 = (2x, 2y) (x, y) * (2 0) = (2x, 2y) (0 2)

Linear Algebra And Geometry

@hatcat01

32

slide-33
SLIDE 33

Shear (x, y) * (1 2) = (x, 2x + y) (0 1)

Linear Algebra And Geometry

@hatcat01

33

slide-34
SLIDE 34

Reflect (x, y) * (1 0) = (x, -y) (0 -1)

Linear Algebra And Geometry

@hatcat01

34

slide-35
SLIDE 35

Rotate (x, y) * (cos a -sin a) (sin a cos a) = (x*cos a + y*sin a,

  • x*sin a + y*cos a)

Linear Algebra And Geometry

@hatcat01

35

slide-36
SLIDE 36

Linear Algebra And Geometry

@hatcat01

36

Boost.Geometry

slide-37
SLIDE 37

Linear Algebra And Geometry

@hatcat01

37

Boost.Geometry Barend Gehrels

slide-38
SLIDE 38

Linear Algebra And Geometry

@hatcat01

38

Boost.Geometry Barend Gehrels Geometry classes

slide-39
SLIDE 39

Linear Algebra And Geometry

@hatcat01

39

Boost.Geometry Barend Gehrels Geometry classes Dimension agnostic

slide-40
SLIDE 40

Linear Algebra And Geometry

@hatcat01

40

Boost.Geometry Barend Gehrels Geometry classes Dimension agnostic Distance

slide-41
SLIDE 41

Linear Algebra And Geometry

@hatcat01

41

Boost.Geometry Barend Gehrels Geometry classes Dimension agnostic Distance Coordinate-system agnostic

slide-42
SLIDE 42

What to expect...

  • 0. A brief history of geometry
  • 1. Linear algebra and geometry
  • 2. Lines and curves
  • 3. Polygons, regular and irregular
  • 4. Intersection and precision
  • 5. Summary of classes and functions

@hatcat01

42

slide-43
SLIDE 43

Lines And Curves

@hatcat01

43

x,y in R {-3 <= x <= 5} {y = x/2 + 5/2}

x y

slide-44
SLIDE 44

Lines And Curves

struct line { float gradient; float y_intercept; };

44

@hatcat01

slide-45
SLIDE 45

Lines And Curves

struct line { float gradient; float y_intercept; }; struct line_segment { point p1; point p2; };

45

@hatcat01

slide-46
SLIDE 46

Lines And Curves

Q

46

@hatcat01

slide-47
SLIDE 47

Lines And Curves

Q 3244.7482

47

@hatcat01

slide-48
SLIDE 48

Lines And Curves

48

@hatcat01

slide-49
SLIDE 49

Lines And Curves

49

@hatcat01

slide-50
SLIDE 50

Lines And Curves

50

@hatcat01

slide-51
SLIDE 51

Lines And Curves

class line { std::vector<point> points; };

51

@hatcat01

slide-52
SLIDE 52

Lines And Curves

class line { float gradient; float intercept; };

52

@hatcat01

slide-53
SLIDE 53

Lines And Curves

class line { float gradient; float intercept; point p1; point p2; };

53

@hatcat01

slide-54
SLIDE 54

Lines And Curves

class line { float gradient; float intercept; point p_begin; point p_end; };

54

@hatcat01

slide-55
SLIDE 55

Lines And Curves

Curves

55

@hatcat01

slide-56
SLIDE 56

Lines And Curves

@hatcat01

56

y = x2

x y

slide-57
SLIDE 57

Lines And Curves

57

@hatcat01

slide-58
SLIDE 58

Lines And Curves

class curve { point p1; point p2; point c1; point c2; };

58

@hatcat01

slide-59
SLIDE 59

Lines And Curves

class curve { point p1; point p2; point c1; point c2; }; Quadratic Bézier curve

59

@hatcat01

slide-60
SLIDE 60

Lines And Curves

60

@hatcat01

slide-61
SLIDE 61

Lines And Curves

61

@hatcat01

slide-62
SLIDE 62

Lines And Curves

62

@hatcat01

slide-63
SLIDE 63

Lines And Curves

63

@hatcat01

slide-64
SLIDE 64

Lines And Curves

64

@hatcat01

slide-65
SLIDE 65

Lines And Curves

65

@hatcat01

slide-66
SLIDE 66

Lines And Curves

66

@hatcat01

slide-67
SLIDE 67

Lines And Curves

class curve { point p1; point p2; point control_point; };

67

@hatcat01

slide-68
SLIDE 68

What to expect...

  • 0. A brief history of geometry
  • 1. Linear algebra and geometry
  • 2. Lines and curves
  • 3. Polygons, regular and irregular
  • 4. Intersection and precision
  • 5. Summary of classes and functions

@hatcat01

68

slide-69
SLIDE 69

Polygons, Regular And Irregular

@hatcat01

69

slide-70
SLIDE 70

Polygons, Regular And Irregular

class triangle { point p1; point p2; point p3; };

70

@hatcat01

slide-71
SLIDE 71

Polygons, Regular And Irregular

@hatcat01

71

slide-72
SLIDE 72

Polygons, Regular And Irregular

class square { point p1; point p2; point p3; point p4; };

72

@hatcat01

slide-73
SLIDE 73

Polygons, Regular And Irregular

class polygon { std::vector<point>; };

73

@hatcat01

slide-74
SLIDE 74

Polygons, Regular And Irregular

class regular_polygon { point centre; point p; size_t vertex_count; float orientation; };

74

@hatcat01

slide-75
SLIDE 75

Polygons, Regular And Irregular

75

@hatcat01

x Lots

  • Lots
  • Lots

y Lots

slide-76
SLIDE 76

Polygons, Regular And Irregular

76

@hatcat01

slide-77
SLIDE 77

Polygons, Regular And Irregular

class circle { point centre; float radius; };

77

@hatcat01

slide-78
SLIDE 78

Polygons, Regular And Irregular

78

@hatcat01

slide-79
SLIDE 79

Polygons, Regular And Irregular

class ellipse { point focus_1; point focus_2; float radius; bool major; };

79

@hatcat01

slide-80
SLIDE 80

Polygons, Regular And Irregular

80

@hatcat01

slide-81
SLIDE 81

Polygons, Regular And Irregular

81

@hatcat01

slide-82
SLIDE 82

Polygons, Regular And Irregular

82

@hatcat01

class stadium { point focus_1; point focus_2; float radius; };

slide-83
SLIDE 83

Polygons, Regular And Irregular

83

@hatcat01

slide-84
SLIDE 84

Polygons, Regular And Irregular

84

@hatcat01

class polycurve { std::vector<std::curve> segments; };

slide-85
SLIDE 85

Polygons, Regular And Irregular

85

@hatcat01

class polycurve { std::vector<std::pair<std::point>> segments; std::optional<point> end_point; };

slide-86
SLIDE 86

Polygons, Regular And Irregular

86

@hatcat01

slide-87
SLIDE 87

What to expect...

@hatcat01

87

  • 0. A brief history of geometry
  • 1. Linear algebra and geometry
  • 2. Lines and curves
  • 3. Polygons, regular and irregular
  • 4. Intersection and precision
  • 5. Summary of classes and functions
slide-88
SLIDE 88

Intersection And Precision

Intersection

@hatcat01

88

slide-89
SLIDE 89

Intersection And Precision

Intersection y = x - 1 y = 2x - 4

@hatcat01

89

slide-90
SLIDE 90

Intersection And Precision

Intersection y = x - 1 y = 2x - 4 0 = x - 3 x = 3

@hatcat01

90

slide-91
SLIDE 91

Intersection And Precision

Intersection y = x2 y = x + 3.9

@hatcat01

91

slide-92
SLIDE 92

Intersection And Precision

Intersection y = x2 y = x + 3.9 0 = x2 - x - 3.9 x = 0.5 ± √(4.15)

@hatcat01

92

slide-93
SLIDE 93

Intersection And Precision

Intersection y = x - 2.3 y = x/3

@hatcat01

93

slide-94
SLIDE 94

Intersection And Precision

Intersection y = x - 2.3 y = x/3 0 = 2x/3 - 2.3 x = 3.45

@hatcat01

94

slide-95
SLIDE 95

Intersection And Precision

@hatcat01

95

slide-96
SLIDE 96

Intersection And Precision

Round of applause for the brave volunteer

@hatcat01

96

slide-97
SLIDE 97

Intersection And Precision

Round of applause for the brave volunteer Swords

@hatcat01

97

slide-98
SLIDE 98

Intersection And Precision

Round of applause for the brave volunteer Swords Fast and thin

@hatcat01

98

slide-99
SLIDE 99

Intersection And Precision

Round of applause for the brave volunteer Swords Fast and thin bool intersects(line a, line b);

@hatcat01

99

slide-100
SLIDE 100

Intersection And Precision

Round of applause for the brave volunteer Swords Fast and thin bool intersects(line a, line b); FLT_MIN vs FLT_EPSILON

@hatcat01

100

slide-101
SLIDE 101

Intersection And Precision

bool intersects(line a, line b, float epsilon);

@hatcat01

101

slide-102
SLIDE 102

What to expect

@hatcat01

102

  • 0. A brief history of geometry
  • 1. Linear algebra and geometry
  • 2. Lines and curves
  • 3. Polygons, regular and irregular
  • 4. Intersection and precision
  • 5. Summary of classes and functions
slide-103
SLIDE 103

Summary Of Classes And Functions

std::math

103

@hatcat01

slide-104
SLIDE 104

Summary Of Classes And Functions

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

slide-105
SLIDE 105

Summary Of Classes And Functions

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

slide-106
SLIDE 106

Summary Of Classes And Functions

std::math::path

106

@hatcat01

slide-107
SLIDE 107

Summary Of Classes And Functions

std::math::path 3 (or 4?) control points

107

@hatcat01

slide-108
SLIDE 108

Summary Of Classes And Functions

std::math::path 3 (or 4?) control points std::math::polyline

108

@hatcat01

slide-109
SLIDE 109

Summary Of Classes And Functions

std::math::path 3 (or 4?) control points std::math::polyline std::math::polycurve

109

@hatcat01

slide-110
SLIDE 110

Summary Of Classes And Functions

template <int N, typename coordinate_system> class regular_polygon;

110

@hatcat01

slide-111
SLIDE 111

Summary Of Classes And Functions

template <int N, typename coordinate_system> class regular_polygon; template <typename coordinate_system> using triangle = regular_polygon<3, coordinate_system>;

111

@hatcat01

slide-112
SLIDE 112

Summary Of Classes And Functions

template <int N, typename coordinate_system> class regular_polygon; template <typename coordinate_system> using triangle = regular_polygon<3, coordinate_system>; class circle;

112

@hatcat01

slide-113
SLIDE 113

Summary Of Classes And Functions

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

slide-114
SLIDE 114

Summary Of Classes And Functions

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

slide-115
SLIDE 115

Summary Of Classes And Functions

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

slide-116
SLIDE 116

Summary Of Classes And Functions

intersect()

116

@hatcat01

slide-117
SLIDE 117

Summary Of Classes And Functions

intersect() distance()

117

@hatcat01

slide-118
SLIDE 118

Summary Of Classes And Functions

intersect() distance() length()

118

@hatcat01

slide-119
SLIDE 119

Summary Of Classes And Functions

contains()

119

@hatcat01

slide-120
SLIDE 120

Summary Of Classes And Functions

contains() area()

120

@hatcat01

slide-121
SLIDE 121

Summary Of Classes And Functions

contains() area() perimeter()

121

@hatcat01

slide-122
SLIDE 122

Summary Of Classes And Functions

contains() area() perimeter() centroid()

122

@hatcat01

slide-123
SLIDE 123

Summary Of Classes And Functions

contains() area() perimeter() centroid() envelope()

123

@hatcat01

slide-124
SLIDE 124

Thank You!

Ask me two questions.

@hatcat01

124

slide-125
SLIDE 125

Credits and acknowledgements

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