Calculating the mid point in a rotated rectangle side

asked 2013-03-17 02:39:15 -0500

hesperus gravatar image

updated 2013-03-17 02:40:19 -0500


I have a rotated rectangle that is based on a CvBox2D object. The rotated rect contains a moving object, i.e. points of the object.

CvBox2D box = cvMinAreaRect2(pointList)
RotatedRec myRect (box);

I'm trying to calculate the middle point of the two sides (left and right) of this rotating rectangle, i want to know those middle points in each side because that's where my fitting rotating ellipse would be, the problem is I think my math is missing something. for instance, to get to the middle point in the right side, here's what I'm doing:

Point2f rightSide;
float rotationAngle = myRect.angle * (180.0/ CV_PI); // Convert from degrees to radians
rightSide.x = + myRect.size.width/2; // Get to the middle point
rightSide.y =; // Keep the y coordinate the same as the center
// Apply the rotation equation, i'm not updating y because I always have the most up to 
// date y coordinate from the center position
rightSide.x = (rightSide.x * cos(rotationAngle)) - (rightSide.y * sin(rotationAngle));

Of course the object is moving randomly within the screen, and so the rotated rectangle is moving along with it. Unfortunately the above piece of code doesn't produce the middle point in the right side of the rotating rectangle, I can tell because I'm actually drawing the point. I'm following a similar approach for the left side. Just wondering if anybody can offer any ideas ? Is it the angle ? Do I have to deal with the fact that sometimes the angle can be in negative and I have to figure out which quarter it lies within ? Is the angle given by the rotated rect is the rotation angle to begin with ? I tried another approach where I get the vertices (i.e. the corners) of the rotated rect and then move to those middle points but that did not work out either.

I'm sure my math is missing something somewhere, I noticed that someone was having a similar problem here ( but I did not want to hijack the thread.

Appreciate the help, thanks in advance.

edit retag flag offensive close merge delete


Hi hesperus,

I have the same problem as you. Did you find a solution?

Thanks very much.

aimee gravatar imageaimee ( 2013-07-17 04:16:55 -0500 )edit