简体   繁体   English

QPainter-沿圆画对象

[英]QPainter - draw objects along a circle

I would like to draw those black dots around the whole circle with regular spacing in between each other (rough image below). 我想在整个圆上画出黑点,彼此之间有规则的间距(下图为粗图)。 Those black dots should sit directly on the circle. 这些黑点应直接位于圆上。 Is there an easy way to do it somehow with painter.drawArc() function or something like that? 是否有一个简单的方法可以用painter.drawArc()函数或类似的方法做到这一点?

期望的输出

No, there isn't. 不,没有。 I am afraid you will have to use... math ! 恐怕您将不得不使用...数学

Actually, you could get away without that. 实际上,如果没有这些,您可能会逃脱。 For sweeping around a circle in particular there is an easy way to do it by transforming the painter. 特别是要绕一个圆圈扫掠时,有一种简单的方法可以通过变换画家来完成。 You initially transform the painter to the center of the circle, and draw the first dot at the circle's 12 o'clock position. 首先,将画家变换到圆的中心,然后在圆的12点位置绘制第一个点。 That means drawing it into negative y space. 这意味着将其绘制到负y空间。 Then you simply rotate the painter by 360 / numOfObjects degree and draw the same circle again. 然后,您只需将画家旋转360 / numOfObjects度,然后再次绘制相同的圆。

They key thing here is to transform the painter to the center and draw the object offset, because otherwise it will be more complicated to calculate the position and angle yourself. 他们这里的关键是将画家变换到中心并绘制对象偏移,因为否则会自己计算位置和角度会更加复杂。 The angle doesn't play a role here, since you are drawing dots, but it will make a huge difference if you draw something other than dots. 角度在这里不起作用,因为您正在绘制点,但是如果您绘制的不是点,则角度将有很大的不同。 This way you can easily sweep the circle by rotating the painter around its origin. 这样,您可以绕着原点旋转画家轻松地扫过圆圈。

To put it in pseudo code: 将其放入伪代码中:

draw big circle
move painter to big circle center
degree = 360 / numOfObjects
while numOfObjects--
  draw dot at 12 o'clock
  rotate painter by degree

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM