Distance from center of an equilateral n-gon in given angle

geometrytrigonometry

I'm currently working on a graph visualization that should have arrow links to other nodes where the tip of the array follows the nodes border. I need to calculate the distance of the center of an n-gon to its border for a given angle.

This is trivial for a circle node with it's radius, as the tip of the arrow needs to be radius away from the center of the circle.

It is already trickier for an equilateral triangle but this solution works: Find distance from center of equilateral triangle to edge in given angle, see example of a triangle.

I was now thinking that there must be a way to calculate this distance for any equilateral n-gon as I want to visualize nodes but I just can't come up with anything, see this pentagon as an example.

So I guess there is a way to calculate this distance for any equilateral n-gon just by the parameters angle and n for the corner count, isn't it?

Thanks in advance!

Best Answer

For simplicity, assume the circumradius of the polygon is $1$. The inradius of the polygon is $r=\cos\frac\pi n$.

Suppose your ray is at some angle $\theta$ from an inradius, and that it hits the polygon at a distance $d$. We then have $\cos\theta=\frac rd$, so

$$d=\frac r{\cos\theta}=\frac{\cos\frac\pi n}{\cos\theta}$$

as illustrated below:

$\hskip{3cm}$enter image description here

Related Question