Calculate polygon corner coordinate

509 Views Asked by At

I have a program to guide a turtle running inside a polygon which have 3 to 8 equally corners (360/corners) and all the edge are have the same length (600 pixel to be exact). I start to draw that polygon at an coordinate of (-300,300). Is there a simple formula to calculate the coordinate all corners left?

Example: 3 corners polygon

Example: 3 corners polygon

1

There are 1 best solutions below

0
On BEST ANSWER

I'm not sure how you need to do this, but all n-gons are simply a linear transformation or coordinate change of a base n-gon.

Also any of these n-gons can be constructed from the question's attached triangle, but a sorting to find outside points would be necessary.

Maybe go around the perimeter calculating lines and slopes, but this still doesn't yield a single function.

If the shape can be circumscribed, the circle could be parameterized in terms of arc length, that should work.

Diameter $$D=s \ csc(\frac{\pi}{n})$$

where $s$ is pixel length of ngon side, $n$ is number of sides.

So all circles represent a ngon, now consider parameterized circle $f(l)=\langle u(l), v(l) \rangle$

$$f(l)=\langle L+\frac{D}{2} cos(\frac{2l \pi}{n}),H+ \frac{D}{2} sin(\frac{2l \pi}{n}) \rangle$$

were $l$ is an integer for the $n$th side. To find $L$ and $H$ use the fact that one of the $l$ is $(-300,300)$. Which $l$, who knows because you haven't mentioned the orientations.

$$f(l)=\langle L+\frac{D}{2} cos(\frac{2l \pi}{n}+\theta),H+ \frac{D}{2} sin(\frac{2l \pi}{n}+\theta) \rangle$$

Now $\theta$ can be used to specify the orientation. Like $$0 \le \theta \le \frac{2 \pi}{n}$$

Increasing $\theta$ will rotate counter clockwise.