我正在尝试在圆上绘制小部件,为此我需要将小部件绘制为弧形。我知道小部件的数量(比方说),然后每个小部件从原点到圆周呈 36 度角。我拥有的信息是圆心、半径,并且我知道每个此类小部件在圆周上的起点和终点。
这是通过做计算的
dx = int(round(400 + 300 * np.cos(angle)))
dy = int(round(400 + 300 * np.sin(angle)))
其中 角度 = 2 * np.pi/15
我通过 for 循环计算角度的新值,它基本上是 angle * i where i = (1, 10)
我不明白 QPainter 中弧函数的起始角度和跨度角度。 QPainter Arc .我用谷歌搜索并没有找到很多术语。也许对他们有不同的称呼。
所以问题是我在圆周、圆心和半径上有一个起点和一个终点,我如何使用它们绘制圆弧,这样我得到的东西看起来像:
我试过的是,我可以计算出两个端点的中心点(cx),如果我从圆心到这个点cx画一条线,那么我可以计算出这个点的圆周距离本质上是我的宽度,但如何获得正确的方向以将它们表示为圆圈。
我的布局不是圆形,而是像这样只有线条,但我想像马戏团一样。 My image
最佳答案
I don't understand the start angle and span angle for the arcs function in QPainter.QPainter Arc.
为什么?恕我直言,文档非常清楚:
The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360).
这意味着您的单位是 1/16º。例如。 45º 是 45*16 个单位。
Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position."
这意味着 90*16 点位于 12 点钟位置(从 3 点钟方向逆时针旋转 90º),而 -90*16 点位于 6 点钟位置。
当然,“零”度仅对起始角度有意义。跨度角表示弧线多远,以及在哪个方向。
例如,要从 3 点到 12 点画一条弧
painter.drawArc(rect, 0, 90*16)
*or*
painter.drawArc(rect, 90*16, -90*16)
但是要从 3 点到 6 点画一条弧线,你会这样做
painter.drawArc(rect, 0, -90*16)
*or*
painter.drawArc(rect, -90*16, 90*16)
圆弧不是使用中心和半径指定的,而是使用边界矩形指定的。如果弧是一个完整的椭圆,它将被刻在矩形中 - 弧是隐式椭圆弧。
因此,给定x
和y
中心点,以及r
为圆半径,边界矩形是
rect = QRect(x-r, y-r, 2*r, 2*r)
关于python - 在 Pyside 中绘制圆弧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22701781/