2

Rectangle example

I would like to check if two polygons (number of vectors unclear) have the same shape. Without rotations this is easy, but how do I do this with rotated polygons? I need to know the rotation angle, too.

boolean polygonsHaveSameShape(PVector[] polygon1, PVector[] polygon2){
  …
}

float getRotationAngle(PVector[] polygon1, PVector[] polygon2){
  …
}
Pwdr
  • 3,712
  • 4
  • 28
  • 38

1 Answers1

3

With a small number of vertices it might be worth checking the distances between each vertex and the others.

In your square example dist(p1,p2), dist(p1,p3), dist(p1,p4), dist(p2,p3), dist(p2,p4) and dist(p3,p4). These values will exist for each polygon. There will be a point that has the same distance set as p1, and as p2, and so on.

Once you have a vertex in one polygon where all the distances connected to it are the same as those in the second polygon then you can use one of those lines to determine the angle of rotation.

Hope that made sense.

Dave
  • 145
  • 4
  • That’s a good idea. Number of vertices will be 3–8. Any idea on the angle then? – Pwdr Jun 24 '14 at 09:44