简体   繁体   English

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

[英]Calculate angles that are in degrees (clockwise) to radians (counter clockwise)

First, I am aware of how converting degrees in radians.首先,我知道如何以弧度转换度数。

I need to draw an arc given a coordinate, radius, and two angles in degrees clockwise in pygame .我需要在pygame中给定坐标、半径和两个角度(以度数为单位)绘制一个弧。 For example:例如:

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

should draw something like应该画类似的东西

在此处输入图像描述

and

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

should draw something like应该画类似的东西

在此处输入图像描述

etc.等等

I have tried reverting the angle (ie 360 - angle ) but pygame draws the arc in reverse;我尝试过反转角度(即360 - angle ),但 pygame 会反向绘制弧线; instead of a 45⁹ arc in the last image, I get a 270⁹ arc that is the complement of what I want.而不是最后一张图像中的 45⁹ 弧,我得到了 270⁹ 弧,这是我想要的补充。

I guess I'm having a brain fart day because I can't figure this out.我想我脑子里放屁一天,因为我想不通。 Thank you!谢谢!


Edit : I may have an answer, though I'm not sure if it is a good one.编辑:我可能有一个答案,但我不确定它是否是一个好的答案。 If I reverse the angles and negate them, it seems to draw them correctly clockwise.如果我反转角度并否定它们,它似乎是顺时针正确绘制它们。 For example, given the first example:例如,给定第一个示例:

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

seems to correctly draws the arc where expected.似乎正确地在预期的地方绘制了弧线。

If you want to draw an clockwise arc, then you've to invert the angles and you've to swap the start and end angle:如果要绘制顺时针圆弧,则必须反转角度,并且必须交换开始角度和结束角度:

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)

eg:例如:

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

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

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