Plots the Bezier curve using matplotlib plotting capabilities. step_size: defines the step(s) at which to evaluate the Bezier curve. The smaller the step size, the finer the curve produced.
(self, step_size: float = 0.01)
| 73 | return (x, y) |
| 74 | |
| 75 | def plot_curve(self, step_size: float = 0.01): |
| 76 | """ |
| 77 | Plots the Bezier curve using matplotlib plotting capabilities. |
| 78 | step_size: defines the step(s) at which to evaluate the Bezier curve. |
| 79 | The smaller the step size, the finer the curve produced. |
| 80 | """ |
| 81 | from matplotlib import pyplot as plt |
| 82 | |
| 83 | to_plot_x: list[float] = [] # x coordinates of points to plot |
| 84 | to_plot_y: list[float] = [] # y coordinates of points to plot |
| 85 | |
| 86 | t = 0.0 |
| 87 | while t <= 1: |
| 88 | value = self.bezier_curve_function(t) |
| 89 | to_plot_x.append(value[0]) |
| 90 | to_plot_y.append(value[1]) |
| 91 | t += step_size |
| 92 | |
| 93 | x = [i[0] for i in self.list_of_points] |
| 94 | y = [i[1] for i in self.list_of_points] |
| 95 | |
| 96 | plt.plot( |
| 97 | to_plot_x, |
| 98 | to_plot_y, |
| 99 | color="blue", |
| 100 | label="Curve of Degree " + str(self.degree), |
| 101 | ) |
| 102 | plt.scatter(x, y, color="red", label="Control Points") |
| 103 | plt.legend() |
| 104 | plt.show() |
| 105 | |
| 106 | |
| 107 | if __name__ == "__main__": |
no test coverage detected