旋转Tkinter画布中的线条

2024-10-01 19:19:52 发布

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

我在画布上有一条线,我想旋转x度,同时保持起点在canvs的中间,我想知道计算终点坐标的公式是什么?,有点像

degrees=xnumberofdegrees
lineEndPoint=degrees*someformulaforxandy
canvas = Canvas(root, width=500, height=500, bg="white")
canvas.pack()
rotatedline=space.create_line(250,250,lineEndPoint)    

起点应该总是250250,因为画布的大小是500x500,所以我只需要结束点。欢迎任何帮助。在


Tags: 画布rootwidth公式canvasbgwhite起点
1条回答
网友
1楼 · 发布于 2024-10-01 19:19:52

三角法的应用相当简单。在

angle_in_radians = angle_in_degrees * math.pi / 180
line_length = 100
center_x = 250
center_y = 250
end_x = center_x + line_length * math.cos(angle_in_radians)
end_y = center_y + line_length * math.sin(angle_in_radians)

相关问题 更多 >

    热门问题