I am drawing an ellipse using QPainterPath
using three mouse clicks. The major and minor axis of the ellipse remain parallel to the principal coordinate axis.
The first click determines the center of the ellipse. The second click's position is used to compute length of major axis and that of third click is used to determine length of minor axis.
Irrespective of the position of the clicks, the ellipse has its axis parallel to the principal axis. How do I set the orientation of the ellipse according to the mouse clicks' position?
I have computed the angle of the line joining first point and second point as:
theta = atan2((p2.y()-p1.y()),(p2.x()-p1.x())) * (180/M_PI);
My bounding rectangle looks like:
QRectF MyEllipse::boundingRect() const
{
return QRectF(p1.x()-majRadius, p1.y()-minRadius, 2 * majRadius, 2 * minRadius).normalized();
}
Then I paint it using:
QPainterPath ellipse;
ellipse.moveTo(p2.x()*cos(theta),p2.y()*sin(theta));
ellipse.arcTo(boundingRect(), theta, theta+360);
QPen paintpen(Qt::black);
paintpen.setWidth(1);
painter->setRenderHint(QPainter::Antialiasing);
painter->setPen(paintpen);
painter->drawPath(ellipse);
How do I get the ellipse properly oriented as per the three points?