-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolar_point_map.py
48 lines (39 loc) · 1.26 KB
/
polar_point_map.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
import matplotlib.pyplot as plt
import math
# Function to convert polar coordinates to Cartesian coordinates
def polar_to_cartesian(length, angle):
x = length * math.sin(angle)
y = length * math.cos(angle)
return x, y
def generate_map():
# Read points from the file
points_file = "points2.txt"
points = []
with open(points_file, "r") as file:
for line in file:
length, angle = map(float, line.split())
points.append((length, angle))
# Initialize starting point at the bottom middle of the grid
start_x = 0
start_y = 0
# Plot each line
for length, angle in points:
# Convert polar coordinates to Cartesian coordinates
end_x, end_y = polar_to_cartesian(length, angle)
# Adjust end coordinates relative to starting point
end_x += start_x
end_y += start_y
# Plot line
plt.plot([start_x, end_x], [start_y, end_y])
# Update starting point for the next line
start_x = end_x
start_y = end_y
# Set axis limits and labels
plt.xlim(-4, 4)
plt.ylim(0, 3)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Theseus III Map')
plt.grid(True)
# Show plot
plt.show()