尝试在 tkinter python 中旋转具有复数的三角形
第一个方法是我的,另外两个来自这里 http://effbot.org/zone/tkinter-complex-canvas.htm
所以我调用旋转方法,该方法调用第二个方法,该方法调用第一个方法。第一个从传递的角度获取 xy 坐标,然后使用它们来平移三角形。
self.x 和 self.y 是三角形画布上的坐标,三角形下线的中间,
我想还有另一种方法可以做到这一点,更简单。
顺便说一句,我发现了这个,但它并没有真正帮助
the first method is mine, the other two are from here
http://effbot.org/zone/tkinter-complex-canvas.htm
so i call the rotate method that calls the second one that calls the first one. the first one gets the xy coordinates from the angle that is passed, and then work with them to translate the triangle.
self.x and self.y are the coordinates on the canvas of the triangle, the middle of the lower line of the triangle
i guess there's another way to do this, much simpler.
and i have found this btw, but it doesn't really help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的帖子暗示了理解如何使用复数旋转三角形的困难。
在阅读您回复我的答案的评论后,我编辑了我的代码示例以演示一种从键盘输入获取角度的方法。
我没有使用 Tkinter 的经验,所以也许有人可以帮助提供更先进的方法。
摘自 Tkinter:事件和绑定 和 Tkinter Entry Widget
当您输入按键事件时处理程序中,使用 text.get() 检索的 Entry 小部件的文本不包含最新的按键字符。
输入的角度以度为单位,可以为负值。
Your post implied difficulty with understanding how to rotate triangles using complex numbers.
After reading your comment in reply to my answer I have edited my code sample to demonstrate a way to get the angle from keyboard input.
I have no experience with Tkinter so perhaps someone can help with a more state of the art approach.
Gleaned from Tkinter: Events and Bindings and The Tkinter Entry Widget
When you enter the keypress event handler, the Entry widget's text, retrieved with text.get(), doesn't include the latest keypress character.
The angle entered is in degrees and can be negative.
任何东西的旋转最好通过将每个点 (x,y) 表示为复数 x + iy 然后通过乘以复数 cos(angle) + i sin(angle) 来旋转每个点
roitation of anything is best done by expressing every point (x,y) as a complex number x + iy Then Rotate each point by multiplying by the comples number cos(angle) + i sin(angle)