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:

       /          \ 

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:

tempX = (point.x * cos(angleToRad(10))) - (point.y * sin(angleToRad(10)));

tempY = (point.x * sin(angleToRad(10))) + (point.y * cos(angleToRad(10)));

For counter clockwise:

tempX = (point.x * cos(angleToRad(350))) - (point.y * sin(angleToRad(350)));

tempY = (point.x * sin(angleToRad(350)) + (point.y * cos(angleToRad(10350));

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!

  • $\begingroup$ 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. $\endgroup$ – 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)$

  • $\begingroup$ This worked! Thank you for the explanation. $\endgroup$ – user3245474 Apr 5 '15 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.