MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / plot_curve

Method plot_curve

graphics/bezier_curve.py:75–104  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
107if __name__ == "__main__":

Callers 1

bezier_curve.pyFile · 0.80

Calls 4

bezier_curve_functionMethod · 0.95
plotMethod · 0.80
showMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected