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

Method bezier_curve_function

graphics/bezier_curve.py:49–73  ·  view source on GitHub ↗

The function to produce the values of the Bezier curve at time t. t: the value of time t at which to evaluate the Bezier function Returns the x, y coordinates of the Bezier curve at time t. The first point in the curve is when t = 0. The last poin

(self, t: float)

Source from the content-addressed store, hash-verified

47 return output_values
48
49 def bezier_curve_function(self, t: float) -> tuple[float, float]:
50 """
51 The function to produce the values of the Bezier curve at time t.
52 t: the value of time t at which to evaluate the Bezier function
53 Returns the x, y coordinates of the Bezier curve at time t.
54 The first point in the curve is when t = 0.
55 The last point in the curve is when t = 1.
56
57 >>> curve = BezierCurve([(1,1), (1,2)])
58 >>> tuple(float(x) for x in curve.bezier_curve_function(0))
59 (1.0, 1.0)
60 >>> tuple(float(x) for x in curve.bezier_curve_function(1))
61 (1.0, 2.0)
62 """
63
64 assert 0 <= t <= 1, "Time t must be between 0 and 1."
65
66 basis_function = self.basis_function(t)
67 x = 0.0
68 y = 0.0
69 for i in range(len(self.list_of_points)):
70 # For all points, sum up the product of i-th basis function and i-th point.
71 x += basis_function[i] * self.list_of_points[i][0]
72 y += basis_function[i] * self.list_of_points[i][1]
73 return (x, y)
74
75 def plot_curve(self, step_size: float = 0.01):
76 """

Callers 1

plot_curveMethod · 0.95

Calls 1

basis_functionMethod · 0.95

Tested by

no test coverage detected