-
Notifications
You must be signed in to change notification settings - Fork 1
/
chasing_vectorv2.py
53 lines (42 loc) · 1.44 KB
/
chasing_vectorv2.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import matplotlib.pyplot as plt
def draw_vectors(plt, vectors):
for i, vector in enumerate(vectors):
if (i==0):
current_point=vector
points = [current_point]
continue
next_point = (current_point[0] + vector[0], current_point[1] + vector[1])
points.append(next_point)
current_point = next_point
plot_lines(plt, points)
return points
def gen_new_subset(fraction, points):
for i, vector in enumerate(points):
if i == 0:
prev_vector = vector
new_points=[prev_vector]
continue
new_vector = (prev_vector[0] + fraction * (vector[0] - prev_vector[0]), prev_vector[1] + fraction * (vector[1] - prev_vector[1]))
new_points.append(new_vector)
prev_vector=new_vector
print(new_points)
return new_points
def plot_lines(plt, points):
x_coords, y_coords = zip(*points)
plt.plot(x_coords, y_coords, marker='o')
# Initial conditions
vectors = [(0, 0), (0, 1), (1, 1), (1, 0)]
fraction = 0.1
cycles = 10 # Number of cycles to apply
# Apply the vectors and generate the path
plt.figure(figsize=(6, 6))
for cycle in range(cycles):
#prev_polygon=draw_vectors(plt, vectors)
plot_lines(plt, vectors)
vectors=gen_new_subset(fraction, vectors)
plt.title('Path Generated by Successive Vector Application')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()
# Plot the resulting path