Apologies, in my previous answer, I misunderstood the question.
Here is one hit on the algorithm (not necessarily the most optimal way, but the way). All you need is the ability to render the polygon and the main rotation.

, , ( , , , ).
Edit
" ". , , .
, , :

, , . , .
, - , - , , , . , 2- 4- ( - , ). , , 4- 360 .