import matplotlib.pyplot as plt import numpy as np # Function to draw a polygon def draw_polygon(num_sides, side_length): angle = 2 * np.pi / num_sides points = [ (np.cos(i * angle) * side_length, np.sin(i * angle) * side_length) for i in range(num_sides) ] points.append(points[0]) # Close the polygon by adding the first point at the end return zip(*points) # Set the number of sides and the side length num_sides = 6 side_length = 1 # Length will be scaled automatically # Get the polygon points x, y = draw_polygon(num_sides, side_length) # Plot the polygon plt.figure() plt.plot(x, y, marker='o') plt.title(f'{num_sides}-sided Polygon') plt.axis('equal') # Equal scaling for x and y axes plt.show()