【问题标题】:Rotate line in Tkinter Canvas在 Tkinter Canvas 中旋转线
【发布时间】:2015-05-01 15:26:21
【问题描述】:

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

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

起点应该始终是 250,250,因为画布的大小是 500x500,所以我只需要终点。欢迎任何帮助。

【问题讨论】:

  • 我对这个问题感到非常失望 - 为什么不是关于如何旋转Canvas 中的现有行?可以移动现有对象(“椭圆”等),但如果我们想任意更改端点怎么办?

标签: python canvas tkinter line


【解决方案1】:

三角函数的应用非常简单。

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)

【讨论】:

    猜你喜欢
    • 2019-04-06
    • 2018-12-18
    • 2017-02-01
    • 1970-01-01
    • 2019-05-29
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多