OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 17 Mar 2013 02:39:15 -0500Calculating the mid point in a rotated rectangle sidehttp://answers.opencv.org/question/9457/calculating-the-mid-point-in-a-rotated-rectangle-side/Hi,
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.center.x + myRect.size.width/2; // Get to the middle point
rightSide.y = myRect.center.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 (http://answers.opencv.org/question/1945/fast-way-to-draw-ellipse-axes/) but I did not want to hijack the thread.
Appreciate the help, thanks in advance.hesperusSun, 17 Mar 2013 02:39:15 -0500http://answers.opencv.org/question/9457/