Firstly just to apologise, I posted this on mathoverflow before realising it was focused on research level mathematics.

If I have a regular polygon that is centred at the origin. Then take the difference between all vertices.

Let $U$ = the maximum $x$ difference

Let $V$ = the maximum $y$ difference

I want to figure out the angle of rotation that creates the maximum

$$W = U + V \, .$$

So for example imagine a line (I know it's not a polygon); if the angle of rotation is $0$ then its vertices are at $( 1, 0 )$ and $( -1, 0 )$

$$ U = 1 - (-1) = 2\\ V = 0 - 0 = 0 $$

So $W = 2 + 0 = 2$.

The optimum is 45 degrees of rotation in which case

$$ U = 0.707 - -0.707 = 1.414 \\ V = 0.707 - -0.707 = 1.414 $$

So $W = 2.828$.

If my calculations are correct, an equilateral triangle's optimum is $45$ degrees as well. However its obvious to see the optimum for a square is 0 since the vertices align perfectly with $x,y$ axis (i.e., $(1,0)$, $(0,1)$, $(-1,0)$ and $(0,-1)$).

Hopefully I've explained it well enough. I can find the solution for single instance of the problem using graphs and derivatives BUT it takes a long time. I'm looking for a general purpose algorithm as this is going to be used in some software I'm writing.

Thanks in advance.


PS I forgot to mention that there'll be multiple solutions due to symmetry. So the line's optimum is $45, 135, 225, 315$. I believe the triangles is $15 + 30n$, i.e. $15, 45, 75, \dots$

PPS The vertices are generated using the following formula:

Let $n$ = number of sides

Let $c = 360 / n$

For all $i: 0 \le i \lt n$

$V_i = ( \cos(i \cdot c ), \sin( i \cdot c ) )$

E.g. a regular triangles vertices are:

$V_0 =(\cos(0^\circ), \sin(0^\circ) ) = (1, 0)$
$V_1 =(\cos(120^\circ), \sin(120^\circ) ) = (-0.5, 0.866)$
$V_2 =(\cos(240^\circ), \sin(240^\circ) ) = (-0.5, 0.866)$

  • $\begingroup$ @Ross thanks for the reply. I don't quite understand it though. I've appended a PPS to the original question which describes how the vertices are generated so there is no ambiguity. Firstly I agree/understand that 4n sided shapes will have an easy optimum. Using my convention 0 degrees rotation. However that leaves 4n + 1, 4n + 2 and 4n + 3 and you seem to only tackle 4n + 2. Then I don't quite understand how you only generate 4 points when n could be anything. As such I can't follow the next step which calculates the max x and y distances U and V. $\endgroup$ – Iain Fraser Jun 12 '13 at 20:27

You need to define what the angle of rotation is measured from. I would have taken zero rotation for the square to be with the sides parallel to the axes. Having a corner on the axes is clearly optimal for $4n$ sided polygons. For $4n+2$ sided polygons it will not be optimal because you gain more from rotating the flat sides than you lose by rotating the points.

To be exact, let $0$ represent having points on the $x$ axis. We start with points $(1,0), (\cos \frac {2n}{4n+2} \pi ,\sin \frac {2n}{4n+2}\pi),(-1,0), (-\cos \frac {2n}{4n+2} \pi ,-\sin \frac {2n}{4n+2}\pi)$ and if we rotate counterclockwise by $\theta$ we get $U=2 \cos \theta,V=2\sin (\frac {2n}{4n+2}\pi+\theta)$ We add these up, differentiate, set to zero, etc. $$U+V=2 \cos \theta +2\sin \left(\frac {2n}{4n+2}\pi+\theta\right)\\\frac d{d\theta}(U+V)=-2 \sin \theta+2\cos \left(\frac {2n}{4n+2}\pi+\theta\right)\\0=-2 \sin \theta +2\cos\left(\frac {2n}{4n+2}\pi \right) \cos \theta-2\sin\left( \frac {2n}{4n+2}\pi\right)\sin \theta\\\tan \theta=\frac{\cos\left(\frac {2n}{4n+2}\pi \right)} {\sin\left( \frac {2n}{4n+2}\pi\right)+2}$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.