Original Post
Hi,
I would like to make an ireguler 4 sided polygon perfectly square.
To do this I have simply calculated the average length of the polygon sides. Then lined up the vertices to ''virtuals'' diagonals from the polygons center.
My problem is, It only works with 2D. I need to take into account the orientation of the original polygon, so the resulting polygon is at the same angle the original polygon was.
How can I go about this?
my current code in pseudocode is:
// Calculated Edge lengths beforehand ... // Get the average edge length AverageEdge = (Edge1+Edge2+Edge3+Edge4) / 4; // Get the Center of the polygon (v1,v2,v3,v4 are vectors) Center = (v1+v2+v3+v4)/4; // Use size to position the vertices in the correct place Size = AverageEdge/2; //move v1 to bottom-left of ''square'' v1 = Center; v1.x -= Size; v1.y -= Size //move v2 to top-left of ''square'' v2 = Center; v2.x -= Size; v2.y += Size //move v3 to top-right of ''square'' v3 = Center; v3.x += Size; v3.y += Size //move v4 to bottom-right of ''square'' v4 = Center; v4.x += Size; v4.y -= SizeAs you can see that is ok for 2D when the orientation isn''t important. Thanks