doris
15th February 2017, 03:12
123351233612336
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:
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 topLeft(x,y);
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..
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:
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 topLeft(x,y);
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..