2 Attachment(s)
drawArc in the rectangle issues
Attachment 12335Attachment 12336Attachment 12336
my program will get the startpoints(x,y) and calculate width and height when you draw on the scene, the attached photo shows it.
the problem is i want to draw a perfect arc in the middle of rectangle as the sketch one attached.
my code as below:
Code:
void ResizableRectMarker
::paintArc1(int x,
int y,
int width,
int height,
QPainter* painter
) {
double radius = sqrt(pow(0.5*width,2)+pow(0.5*height,2));
double step = sqrt(pow(radius,2)-pow(0.5*width,2));
QPointF bottomRight
(x
+width,y
+height
);
QRectF rect
(topLeft, bottomRight
);
int startAngle = atan2(0.5*width,step)* 180 / M_PI * 16;
int spanAngle = 2*startAngle;
qDebug() << "start angle:" << startAngle << "|" << "spanAngle:" << spanAngle;
painter->drawArc(rect, startAngle, spanAngle);
}
the problem is the the arc drawn is not in the center, and also if the rectangle is not a square, the arc is wired.
any solution for it.
newbie here..
Re: drawArc in the rectangle issues
It is not entirely clear what your objective is.
Your drawing suggests that you want a circle arc that intersects the rectangle on its left and right side in the middle, the screenshot and code indicates an ellipse arc that fits into the rectangle.
Cheers,
_
Re: drawArc in the rectangle issues
I think this is what you want
Code:
{
protected:
{
const double radius = qSqrt(qPow(width()/2.0, 2) + qPow(height()/2.0, 2));
const int startAngle = qAtan((width()/2.0)/radius) * 180 / M_PI * 16;
const int spanAngle = (90 - startAngle) * 2 * 16;
const QRect rect
= event
->rect
().
adjusted(-(radius
-width
()/2.0), height
()-radius,
(radius
-width
()/2.0), radius
);
painter.drawArc(rect, startAngle, spanAngle);
}
};
int main(int argc, char *argv[])
{
ArcWidget widget;
widget.show();
return app.exec();
}