Auto create polygon AS3

Made a Flash on Wonderfl the other day.

My friend studying for his PhD at Georgia Tech in architecture called me regarding a problem. He said,

“I need to program something to create a polygon from points. Right now, the points are not being drawn in the right order so lines are being overlapped. How do I have the program draw them in the right order?”

So I came up with a theory of how to do it. The idea is that you find the average point between the points, and from that point you find the arc tangent to each of the points and order the points based on their angle to the center. This idea would only work in 2D, but I’m sure there is a general way to do it for all dimensions.

Here is the code written in actionscript. You can click to add a point and ctrl+click to delete a point. I put it on wonderfl because I am thinking some people could fork some more interesting things from it.

Auto create Polygon – wonderfl build flash online