python - 在 Tkinter Canvas 中旋转线

标签 python canvas tkinter line

我在 Canvas 上有一条线,我想将其旋转x度,同时将起点保持在 Canvas 的中间,我想知道计算终点坐标的公式是什么?,类似的东西

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,因为 Canvas 的大小为 500x500,所以我只需要终点。欢迎任何帮助。

最佳答案

三角学的非常简单的应用。

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)

关于python - 在 Tkinter Canvas 中旋转线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29989792/

相关文章:

python - combine_first 和 fillna 有什么区别?

javascript - 如何根据Fabric.js中绘制的图像获取椭圆的正确坐标

java - 如何使用来自图像的数据 URI 作为 InputStream?

python - 使用 tkinter 在 Windows 上使用全局热键

python - Pandas 到多个字典对象

python - Flask 应用程序仅对本地主机可见

html - 贝塞尔曲线总是相同的长度

在 for 循环中创建的组合框中的 python tkinter 引用

带有 Tkinter 的 Python 聊天机器人

python - 在 python 中编写一个简单的 MongoDB 模块