以度(顺时针)到弧度(逆时针)为单位计算角度

2024-09-28 17:18:14 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我知道如何用弧度转换度。你知道吗

我需要画一个给定坐标,半径和两个角度的弧,在pygame顺时针方向。例如:

point = (50, 50)
startAngle = 320
endAngle = 140

应该画些

enter image description here

以及

point = (50, 50)
startAngle = 90
endAngle = 180

应该画些

enter image description here

等等

我尝试过还原角度(即360 - angle),但pygame反向绘制了弧线;我得到的不是上一张图片中的45⁹弧线,而是270⁹弧线,这是我想要的补充。你知道吗

我想我今天要放屁是因为我搞不懂这个。谢谢您!你知道吗


编辑:我可能有一个答案,但我不确定它是否是一个好的答案。如果我把角度倒过来,把它们取反,它看起来是顺时针画的。例如,第一个例子:

point = (50, 50)
startAngle = 360 - 140
endAngle = 360 - 320

似乎正确地画出了预期的弧线。你知道吗


Tags: 答案编辑半径绘制图片方向pygamepoint
1条回答
网友
1楼 · 发布于 2024-09-28 17:18:14

如果你想画一条顺时针的弧线,那么你必须反转角度,交换开始和结束的角度:

def clockwiseArc(surface, color, point, radius, startAngle, endAngle):
    rect = pygame.Rect(0, 0, radius*2, radius*2)
    rect.center = point

    endRad   = math.radians(-startAngle)
    startRad = math.radians(-endAngle)

    pygame.draw.arc(surface, color, rect, startRad, endRad)

例如:

clockwiseArc(window, (255, 0, 0), (150, 70), 50, 300, 140) 
clockwiseArc(window, (255, 0, 0), (300, 70), 50, 90, 180) 

相关问题 更多 >