依据圆盘,在圆盘里面画12个有等间距的小梯形
时间: 2024-04-05 20:32:38 浏览: 23
好的,您可以使用以下代码在圆盘里面画12个等间距的小梯形:
void QDiscWidget::draw_disc_scale(QPainter &p) {
p.save();
QPen pen(QColor(255, 255, 255));
pen.setWidth(5);
p.setPen(pen);
for (int i = 0; i < 12; ++i) {
QPolygonF polygon;
polygon << QPointF(disc_R - 10, 0)
<< QPointF(disc_R - 3, 0)
<< QPointF(disc_R - 3, -10)
<< QPointF(disc_R - 10, -5);
p.drawPolygon(polygon);
p.rotate(30);
}
p.restore();
}
这段代码会在圆盘上等间距地绘制12个小梯形,每个小梯形之间相隔30度,梯形的顶点分别为(disc_R - 10, 0),(disc_R - 3, 0),(disc_R - 3, -10),(disc_R - 10, -5)。
相关问题
依据圆盘,在圆盘里面画12个有等间距的相同的等腰小梯形
好的,您可以使用以下代码在圆盘里面画12个等间距的相同的等腰小梯形:
void QDiscWidget::draw_disc_scale(QPainter &p) {
p.save();
QPen pen(QColor(255, 255, 255));
pen.setWidth(5);
p.setPen(pen);
float angle = 30;
float edgeLen = 15;
float halfWidth = 3;
for (int i = 0; i < 12; ++i) {
QPolygonF polygon;
polygon << QPointF(disc_R - halfWidth - edgeLen, 0)
<< QPointF(disc_R - halfWidth, 0)
<< QPointF(disc_R - halfWidth, -edgeLen)
<< QPointF(disc_R - halfWidth - edgeLen * qSin(qDegreesToRadians(angle / 2)), -edgeLen);
p.drawPolygon(polygon);
p.rotate(30);
}
p.restore();
}
这段代码会在圆盘上等间距地绘制12个等腰小梯形,每个小梯形之间相隔30度,梯形的顶点分别为(disc_R - halfWidth - edgeLen, 0),(disc_R - halfWidth, 0),(disc_R - halfWidth, -edgeLen),(disc_R - halfWidth - edgeLen * qSin(qDegreesToRadians(angle / 2)), -edgeLen)。其中,angle为小梯形两边夹角的度数,edgeLen为小梯形两边的长度,halfWidth为小梯形上底边的一半长度。
汉诺塔圆盘6个
汉诺塔是一个著名的数学问题,它的规则如下:
有三根柱子和N个圆盘,初始时圆盘从小到大依次放在第一根柱子上,要求把所有圆盘移到第三根柱子上,且每次只能移动一个圆盘,且大盘不能放在小盘上面。
对于6个圆盘的汉诺塔问题,需要64次移动才能完成。具体的移动顺序可以通过递归算法实现,以下是Python代码实现:
```
def hanoi(n, a, b, c):
if n == 1:
print(a, '->', c)
else:
hanoi(n-1, a, c, b)
print(a, '->', c)
hanoi(n-1, b, a, c)
hanoi(6, 'A', 'B', 'C')
```
其中,n表示圆盘的数量,a、b、c分别表示三根柱子的名称。执行上述代码,即可输出6个圆盘的移动方案。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)