-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_beizer_curve.py
More file actions
30 lines (24 loc) · 796 Bytes
/
4_beizer_curve.py
File metadata and controls
30 lines (24 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import numpy as np
import matplotlib.pyplot as plt
control_points = np.array([
[1, 2], # P0: Start point
[3, 8], # P1: First control point
[6, 1], # P2: Second control point
[9, 5] # P3: End point
])
def bezier_curve(t, p):
return (1-t)**3*p[0] + 3*(1-t)**2*t*p[1] + 3*(1-t)*t**2*p[2] + t**3*p[3]
t_values = np.linspace(0, 1, 100)
curve_points = np.array([bezier_curve(t, control_points) for t in t_values])
plt.figure(figsize=(7,7))
plt.plot(curve_points[:,0], curve_points[:,1], 'b-', label='Bezier Curve')
plt.plot(control_points[:,0], control_points[:,1], 'r--', label='Control Points')
plt.xlabel('X')
plt.ylabel('Y')
plt.xlim(0, 10)
plt.ylim(0, 10)
plt.title("Bezier Curve")
plt.gca().set_aspect('equal')
plt.grid(True, linestyle='--')
plt.legend()
plt.show()