-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchasing_vector.py
57 lines (43 loc) · 1.49 KB
/
chasing_vector.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
53
54
55
56
import matplotlib.pyplot as plt
def draw_vectors(plt, start_point, vectors):
points = [start_point]
new_vectors = []
current_point = start_point
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)
def gen_new_vector(fraction, vectors):
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)
prev_vector=vector
vector=vectors[0]
new_vector = (prev_vector[0] + fraction * vector[0], prev_vector[1] + fraction * vector[1])
new_vectors.append(new_vector)
print(new_vectors)
return new_vectors
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.1
cycles = 200 # Number of cycles to apply
# Apply the vectors and generate the path
plt.figure(figsize=(6, 6))
for cycle in range(cycles):
draw_vectors(plt, start_point, vectors)
vectors=gen_new_vector(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