From 996700bec93b94ce4bc2843bf9c95ed611a54fab Mon Sep 17 00:00:00 2001 From: Akbar Rahman Date: Wed, 17 Jan 2024 15:50:25 +0000 Subject: [PATCH] add exercise sheet 8 solution plotter script --- .../Exercise Sheet 8 Solutions.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 uni/mmme/3085_computer_engineering_and_mechatronics/exercise_sheets/mechatronics/Exercise Sheet 8 Solutions.py diff --git a/uni/mmme/3085_computer_engineering_and_mechatronics/exercise_sheets/mechatronics/Exercise Sheet 8 Solutions.py b/uni/mmme/3085_computer_engineering_and_mechatronics/exercise_sheets/mechatronics/Exercise Sheet 8 Solutions.py new file mode 100644 index 0000000..4d9f851 --- /dev/null +++ b/uni/mmme/3085_computer_engineering_and_mechatronics/exercise_sheets/mechatronics/Exercise Sheet 8 Solutions.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# +# Akbar Rahman + +import matplotlib.pyplot as plt + +x0, y0 = (5, 5) +x1, y1 = (18, 16) + +dx = x1 - x0 +dy = y1 - x0 +D = 2 * dy - dx +y = y0 + +print(f"{dx=} {dy=} {D=} {y=}") + +xs = [] +ys = [] + +for x in range(x0, x1 + 1): + # moveto(x, y) + if D > 0: + y += 1 + D -= 2 * dx + + D += 2 * dy + print(f"{D=}\t{x=}\t{y=}") + xs.append(x) + ys.append(y) + +print(f"{xs=}") +print(f"{ys=}") +plt.plot(xs, ys) +plt.show()