# Finding Centre of a Trapezoid for rotation

I'm trying to find the centre of a trapezoid, and am attempting to then rotate it around its centre.

Right now, i'm finding the centre, translating it to the origin, rotating it around the origin, and then translating it back to its original position.

If you view the trapezoid as this:

        a--------b
/          \
c------------d


centreX = (((a.x + b.x) / 2.0) + ((c.x + d.x) / 2.0)) / 2.0;

centreY = ((a.y + c.y) / 2.0);

To find the two centre coordinates but this isn't rotating it around the correct spot.

To do the rotation, I am using this formula on every point:

For clockwise:

For counter clockwise:

i.e. the rotations can only be 10 CW or 10 CCW.

Is there something wrong with my formula that i'm not getting the desired rotation? Thank you!

• Do you assume the trapezoid is initially in the position as drawn? Because in general your formula for y-coordinate of the center is wrong. It's better to use the average $(a+b+c+d)/4$ for both x-and y-coordinates. The rotation formulas are correct. – user147263 Apr 4 '15 at 18:07

1) Find the coordinate $(x_c,y_c)$ of the center with the method suggested in the comment of @pizza, or intersecting the two diagonal of the trapezoid.
2)Translate the center of the coordinate system to $x_c,y_c$. This means that you perform the transformation $(x,y)\rightarrow(X,Y)=(x-x_c, y-y_c)$ for all points (note the minus sign!).
3) Rotate the new coordinates with the formulas in OP: $$R_\theta(X,Y)(X',Y')=(X\cos \theta-Y\sin \theta,X\sin \theta+Y\cos \theta)$$
4) Return to the old coordinate system with an inverse transaltion of the origin:$(X',Y')\rightarrow(x',y')=(X'+x_c, Y'+y_c)$