import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
# --- Circle Parameters ---
circle_diameter = 15 # feet
circle_radius = circle_diameter / 2 # feet
circle_center = (0, 0)
# --- Rectangle Parameters ---
rectangle_width_ft_in = (12, 10) # (feet, inches)
rectangle_height_ft_in = (7, 10) # (feet, inches)
# Convert rectangle dimensions to feet
rectangle_width = rectangle_width_ft_in[0] + rectangle_width_ft_in[1] / 12
rectangle_height = rectangle_height_ft_in[0] + rectangle_height_ft_in[1] / 12
# Calculate bottom-left corner for a centered rectangle
rectangle_bottom_left = (-rectangle_width / 2, -rectangle_height / 2)
# --- Square Post Parameters ---
post_side_inches = 6
post_side_feet = post_side_inches / 12 # 0.5 feet
distance_from_edge_inches = 6
distance_from_edge_feet = distance_from_edge_inches / 12 # 0.5 feet
num_posts = 8
# Calculate the radial distance to the center of each square post
# The innermost edge of the square is at (circle_radius -
# distance_from_edge_feet) from the center.
# So, the center of the square is at (circle_radius - distance_from_edge_feet +
# post_side_feet / 2)
post_center_radius = circle_radius - distance_from_edge_feet - (post_side_feet / 2) # Adjusted based on re-reading "6 inches away from the *inside edge* of the circle". This means the *closest point* of the square to the circle's center is 6" from the circle's edge.
# Correct calculation: the distance is from the circle's *edge* to the *square's
# edge*.
# So, the inner edge of the square is at circle_radius - distance_from_edge_feet
# The center of the square is at (circle_radius - distance_from_edge_feet -
# post_side_feet / 2)
# No, it should be: The inner edge of the square is at distance_from_center =
# circle_radius - distance_from_edge_feet
# The center of the square is at distance_from_center - (post_side_feet / 2) if
# it's placed outside this point.
# Or, if the square's center is 'r', then the closest part of the square is r -
# post_side_feet/2.
# So, r - post_side_feet/2 = circle_radius - distance_from_edge_feet
# r = circle_radius - distance_from_edge_feet + post_side_feet/2
post_center_radius = circle_radius - distance_from_edge_feet - (post_side_feet/2) # Let's assume this means the center of the post is at a radius that places its inner edge 6" from the circle edge.
# Re-reading: "6" away from the inside edge of the circle". This means the
# distance from the circle's inner circumference to the square's outer
# circumference is 6".
# So, the inner edge of the post will be at radius = circle_radius - 0.5 feet.
# The center of the post will be at radius = (circle_radius - 0.5) -
# (post_side_feet / 2)
# This would place the post *inside* that specified distance.
# Let's consider the distance from the center of the circle to the nearest point
# of the square.
# That distance should be (circle_radius - distance_from_edge_feet).
# If the square is aligned, its center is at this distance + half its side.
# So, radial_position_of_square_center = (circle_radius -
# distance_from_edge_feet) + (post_side_feet / 2)
radial_position_of_square_center = (circle_radius - distance_from_edge_feet) - (post_side_feet / 2) # This would place it too close to the center if its inner edge is 6" from circle's edge.
# Let's use the most straightforward interpretation: the point of the square
# closest to the circle's center
# should be at (circle_radius - distance_from_edge_feet).
# This means the center of the square (if its side is aligned with the radius)
# is at:
# radial_position_of_square_center = (circle_radius - distance_from_edge_feet) +
# (post_side_feet / 2)
radial_position_of_square_center = circle_radius - distance_from_edge_feet - (post_side_feet/2) # This makes more sense for "inside edge of circle". The square is 6" away from the edge, meaning there's a 6" gap.
# If the inner edge of the circle is at R=7.5. The gap is 0.5ft. So the outer
# edge of the square is at 7.5 - 0.5 = 7.0.
# The square's center would then be at 7.0 - (0.5/2) = 7.0 - 0.25 = 6.75 feet
# from the center.
# Let's use this interpretation:
post_radial_distance = circle_radius - distance_from_edge_feet - (post_side_feet / 2)
# Create the plot
fig, ax = plt.subplots(figsize=(10, 10)) # Increased figure size for better visibility
# Draw the circle
circle = patches.Circle(circle_center, circle_radius, edgecolor='blue', facecolor='none', linewidth=2, label=f'Circle (Diameter = {circle_diameter} ft)')
ax.add_patch(circle)
# Draw the rectangle
rectangle = patches.Rectangle(rectangle_bottom_left, rectangle_width, rectangle_height, edgecolor='red', facecolor='none', linewidth=2, label=f'Rectangle ({rectangle_width_ft_in[0]}\'{rectangle_width_ft_in[1]}\" x {rectangle_height_ft_in[0]}\'{rectangle_height_ft_in[1]}\")')
ax.add_patch(rectangle)
# Draw the 8 square posts
for i in range(num_posts):
angle_deg = i * (360 / num_posts)
angle_rad = np.deg2rad(angle_deg)
# Calculate the center of the square post
post_center_x = post_radial_distance * np.cos(angle_rad)
post_center_y = post_radial_distance * np.sin(angle_rad)
# Calculate the bottom-left corner of the square post
post_bottom_left_x = post_center_x - (post_side_feet / 2)
post_bottom_left_y = post_center_y - (post_side_feet / 2)
square_post = patches.Rectangle((post_bottom_left_x, post_bottom_left_y), post_side_feet, post_side_feet, edgecolor='green', facecolor='lightgreen', linewidth=1)
ax.add_patch(square_post)
# Add a single label for all posts
ax.add_patch(patches.Rectangle((0, 0), 0, 0, edgecolor='green', facecolor='lightgreen', linewidth=1, label='8 Square Posts (6"x6")'))
# Set plot limits and aspect ratio
ax.set_xlim(circle_center[0] - circle_radius - 1, circle_center[0] + circle_radius + 1)
ax.set_ylim(circle_center[1] - circle_radius - 1, circle_center[1] + circle_radius + 1)
ax.set_aspect('equal', adjustable='box')
# Add labels and title
ax.set_xlabel('X-coordinate (feet)')
ax.set_ylabel('Y-coordinate (feet)')
ax.set_title('Circle with Rectangle and Evenly Spaced Square Posts')
ax.grid(True, linestyle='--', alpha=0.7)
ax.legend(loc='upper right') # Adjust legend location for better fit
# Save the plot
plt.savefig('circle_rectangle_posts_new.png') Click Run or press shift + ENTER to run code