-
Notifications
You must be signed in to change notification settings - Fork 1
/
chasing_vector.py.old2
54 lines (43 loc) · 1.62 KB
/
chasing_vector.py.old2
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
53
import matplotlib.pyplot as plt
def draw_vectors(plt, start_point, vectors, fraction, cycles):
points = [start_point]
new_vectors = []
current_point = start_point
for cycle in range(cycles):
for vector in vectors:
next_point = (current_point[0] + vector[0], current_point[1] + vector[1])
points.append(next_point)
current_point = next_point
plot_lines(plt, points)
points = [start_point]
new_vectors=[]
for i, vector in enumerate(vectors):
if i == 0:
prev_vector = vector
continue
new_vector = (prev_vector[0] + fraction * vector[0], prev_vector[1] + fraction * vector[1])
new_vectors.append(new_vector)
new_point = (vector[0] + fraction * prev_vector[0], vector[1] + fraction * prev_vector[1])
new_vectors.append(new_point)
# Reduce the vectors by the fraction for the next cycle
#vectors = [(v[0] * fraction, v[1] * fraction) for v in vectors]
vectors = new_vectors
new_vectors = []
return
def plot_lines(plt, points):
x_coords, y_coords = zip(*points)
plt.plot(x_coords, y_coords, marker='o')
# Initial conditions
start_point = (0, 0)
vectors = [(1, 0), (0, 1), (-1, 0), (0, -1)]
fraction = 0.90
cycles = 10 # Number of cycles to apply
# Apply the vectors and generate the path
plt.figure(figsize=(6, 6))
draw_vectors(plt, start_point, vectors, fraction, cycles)
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