PDA

View Full Version : QGraphicsView / QPainter / QGraphicsItem arc drawing bug.

kloopa
15th January 2016, 10:46
Hi.

I have arc:

A coordinates (arc start point):
X: 31.963
Y: 70.548

B coordinates (arc end point):
X: 26.963
Y: 65.548

C coordinates (arc center point):
X: 31.963
Y: 65.548

calculated:
startAngle = 90.0
endAngle = 180.0
spanAngle = 90.0

Using calculated data, the arc must be placed between 9 and 12 o'clock:

11646

But its placed between 6 and 9 o'clock:

11647

Why? QPainter / QGraphicsView bug? Or what?

anda_skoa
15th January 2016, 11:20
Are you sure it is a bug?

Angle 0 could be at the horizontal axis pointing right, then 90Â° would be down if the angle is applied clockwise and 180Â° would be to the left.

Cheers,
_

kloopa
15th January 2016, 12:28
Yes, i think a bug found.
I'm calculating angles using:
startangle = (atan2(a.y() - c.y(), a.x() - c.x())*180 / pi)*16
endangle = (atan2(b.y() - c.y(), b.x() - c.x())*180 / pi)*16
spanangle = endangle - startangle

Sometimes angles is + or -. Maybe problem in this?
I can povide coordinates, and you can try to draw using it.

d_stranz
15th January 2016, 15:49
Maybe you are having trouble with QPainter's device coordinate system. 0, 0 is at the top left, and the device coordinates increase as you go right and down. So everything is upside-down with respect to world coordinates.

kloopa
16th January 2016, 08:58
My settings (python3):

graphicsView.scene.setSceneRect(0, 1000, 1000, -1000)
graphicsView.setRenderHints(QPainter.Antialiasing)
graphicsView.scale(2.5, -2.5)

It sets X0.0, Y0.0 to lower left corner.

Arcs:

arcs = [
{'a': QPointF(31.963, 60.548), 'b': QPointF(31.963, 70.548), 'c': QPointF(31.963, 65.548), 'direction': 1},
{'a': QPointF(24.254, 70.548), 'b': QPointF(24.254, 114.148), 'c': QPointF(24.254, 92.348), 'direction': -1},
{'a': QPointF(24.254, 106.548), 'b': QPointF(24.254, 78.148), 'c': QPointF(24.254, 92.348), 'direction': 1},
{'a': QPointF(35.254, 78.148), 'b': QPointF(35.254, 106.548), 'c': QPointF(35.254, 92.348), 'direction': 1},
{'a': QPointF(35.254, 114.148), 'b': QPointF(35.254, 70.548), 'c': QPointF(35.254, 92.348), 'direction': -1},
{'a': QPointF(31.963, 70.548), 'b': QPointF(26.963, 65.548), 'c': QPointF(31.963, 65.548), 'direction': 1}
]

a - arc start point
b - arc end point
c - arc center point
direction - (1 - counter-clockwise) and (-1 - clockwise)

If you don't understand python:

1st Arc (counter-clockwise)
start_point: X31.963 Y60.548
end_point: X31.963 Y70.548
center: X31.963 Y65.548
------------------------------
------------------------------
2nd Arc (clockwise)
start_point: X24.254 Y70.548
end_point: X24.254 Y114.148
center: X24.254 Y92.348
------------------------------
------------------------------
3rd Arc (counter-clockwise)
start_point: X24.254 Y106.548
end_point: X24.254 Y78.148
center: X24.254 Y92.348
------------------------------
------------------------------
4th Arc (counter-clockwise)
start_point: X35.254 Y78.148
end_point: X35.254 Y106.548
center: X35.254 Y92.348
------------------------------
------------------------------
5th Arc (clockwise)
start_point: X35.254 Y114.148
end_point: X35.254 Y70.548
center: X35.254 Y92.348
------------------------------
------------------------------
6th Arc (counter-clockwise)
start_point: X31.963 Y70.548
end_point: X26.963 Y65.548
center: X31.963 Y65.548

calculating arc angles:

startangle = (atan2(a.y() - c.y(), a.x() - c.x())*180 / pi)*16
endangle = (atan2(b.y() - c.y(), b.x() - c.x())*180 / pi)*16
spanangle = endangle - startangle

Try to draw this 6 arcs.

Correct drawing looks like:

11651

Green dot - arc start point
Red dot - arc end point