mmmeff
mmmeff

Reputation: 1033

Rotating a polygon so a specific side is on the bottom

I'm trying to find the angle it would take for me to rotate a polygon so that a specific side is completely horizontal and on the bottom.

For example, a shape like this:

enter image description here

Needs to be rotated so the side with the red square on it is on the bottom and completely horizontal, like this:

enter image description here

So far I've tried several approaches but all end up having strange edge cases where the angle is incorrect.

Upvotes: 0

Views: 160

Answers (1)

MBo
MBo

Reputation: 80197

If you have coordinates of two vertices of this edge (x1,y1) and (x2,y2) in counterclockwise order, then rotation angle is

RotAngle = atan2 (y2-y1, x2-x1)

Upvotes: 1

Related Questions