# How to calculate the center of a regular polygon?

What is the formula for the center of an n-edge regular polygon that has the given segment as its edge?

So, given a segment AB, with endpoints A=(a1,a2) and B=(b1,b2), I need to find out the two points X=(x1,x2) and Y=(y1,y2), such that the n-edge regular polygon with center at X, and the one with center at Y have AB as their edge.

Let $T=\tan(180^{\circ}/n)$. The midpoint of $AB$ is $((a1+b1)/2,(a2+b2)/2)$, the centres would be $$((a1+b1)/2+(a2-b2)/2T,(a2+b2)/2+(b1-a1)/2T)\\ ((a1+b1)/2+(b2-a2)/2T,(a2+b2)/2+(a1-b1)/2T)$$