我正在试着画出下面的图片"一个六角星形或六角星形,在六个顶点和六个交叉点的每一个上都放置数字".
以下是我到目前为止的代码.我被困住了,试图找到六边形的顶点来绘制那里的数字.
import matplotlib.pyplot as plt
import math
def plot_hexagram_with_numbers(side_length):
# Calculate the coordinates for the vertices of the hexagram
vertices = []
mu_hexagon = 360 / 6
for i in range(6):
angle_rad = math.radians(i * mu_hexagon)
x = side_length * math.cos(angle_rad)
y = side_length * math.sin(angle_rad)
vertices.append((x, y))
# Create a list of triangles' vertices for the hexagram
triangles = []
for i in range(6):
triangle = [vertices[i], vertices[(i + 2) % 6], vertices[(i + 4) % 6]]
triangles.append(triangle)
# Plot the hexagram's triangles
for triangle in triangles:
x_coords, y_coords = zip(*triangle)
plt.plot(x_coords, y_coords, 'b-')
# Add numbers at each vertex and intersection of the hexagram
label_distance = side_length / 20 # Adjust this value as needed
for i in range(6):
x, y = vertices[i]
# cant figure out how to find the edges/intersections :(
# Set axis equal and show the plot
plt.axis('equal')
plt.show()
这是上面的代码生成的图像: