Shot distance between center and finish (shot one is blocked by outline of polygon), when central cannon shoot one onto outline, shot one never escape out of polygon.
Polygonal side length: 150 px
Side: 4
Polygon angle: 90° (side toward to 90°)
Example:
90° = 75 px (apothem)
0° = 75 px (apothem)
45° = 106.06601718 px (vertex)
Formula:
Distance (ray-outline) (px) = ?
Direction of center: 100°, or point toward to x/y position of mouse pointer.
Assistant
Let's clarify the problem and break down the solution step-by-step.
Problem Restatement
You have a regular polygon with:
Number of sides ( n = 4 ) (a square),
Side length ( s = 150 ) px,
The polygon is oriented so that one side is at ( 90^\circ ),
You want to find the distance from the center of this polygon to a point on its outline (edge) in a given direction (angle) from the center.
Key points/examples you gave:
At ( 0^\circ ) or ( 90^\circ ), the distance is the apothem: 75 px.
At ( 45^\circ ) (vertex direction), the distance equals the distance from center to vertex: approx 106.066 px.
You want a formula to calculate:
[
\text{distance}(\theta) = \text{distance from center to outline in direction } \theta
]
where (\theta) is the direction angle relative to the polygon center.
Additional Clarifications
The polygon is a square with side ( s = 150 ) px.
The polygon is oriented so one side points at (90^\circ). That means the square is rotated so the top side is horizontal aligned, or more precisely:
For a square, the sides are at (0^\circ, 90^\circ, 180^\circ, 270^\circ) after orientation.
Geometry Facts for a Square
Apothem ( a = \frac{s}{2} = 75 ) px since square's apothem is half the side length (distance from center to midpoint of a side).
Distance from center to vertex ( r_v = \frac{s}{\sqrt{2}} \approx 106.066 ) px.
Objective
Given an angle (\theta), find the distance (d) from center to polygon outline in that direction (like ray casting from center at (\theta)).
Step 1: Model the square position
Assuming square is centered at origin ((0,0)), with vertices at: