PDA

View Full Version : A accuracy problem about QPainterpath.arcTo



lqyp0420
5th April 2016, 14:54
Hi, I have a problem when i use QPainterPath.arcTo, and it puzzls me for a long time. just as the flowing:

r=100.1232131
path=QPainterPath(QPointF(r, 0))
rect=QRectF(-r, -r, 2*r, 2*r)
path.arcTo(rect, 0.0, 78.0)
p2=path.pointAtPercent(1.0)
print QLineF(p2, QPointF(0, 0)).length()

the printed r=100.143731537 not equal the one before

is there some way to improve the accuray or does i make any mistakes in the program?

Thanks for your suggestions and greatly appreciated.

anda_skoa
5th April 2016, 16:57
Which value do you expect the p2 to have?

Cheers,
_

lqyp0420
6th April 2016, 01:07
i expect the length of line berween p2 and center (qpoint(0,0)) equal to the r i set before, but there is some errors.

anda_skoa
6th April 2016, 11:21
Well, the point that has r as its X coordinate is at the beginning of the path.
p2 is not, you've requested it to be the position 1% into the path.

Cheers,
_

lqyp0420
6th April 2016, 13:20
p2=path.pointAtPercent(n)

n between 0.0 to 1.0, when n=1.0 means 100%

rect=QRectF(-r, -r, 2*r, 2*r)
path.arcTo(rect, 0.0, 78.0)

it means that the path is a arc (part of a circle), and the length of each point at the arc between center(QPointF(0,0)) is equal to the r(100.1232131) set before
but why the length between the end point of path (p2) and center is not equal to the r(100.1232131),