【问题标题】:Calculate position after adding an angle添加角度后计算位置
【发布时间】:2021-03-08 20:03:35
【问题描述】:
我正在尝试制作一个类似计算器的程序,它有一个特定的起点,我想在画布上取一个点(我得到了这个点的 x 和 y)。现在,我想从starting_point 的角度加上 30 并计算画布上的点(就像一个圆圈,只是改变它的位置)。
我没有任何关于它的代码。
我知道在数学中我必须考虑一个圆并计算它在圆上的位置,但我不确定如何在编程中做到这一点。如果你能告诉我如何用最好的 python 或其他语言来做,我想知道。
【问题讨论】:
标签:
python-3.x
math
coordinates
angle
【解决方案1】:
这是一个示例代码:
import math
x = int(input('x position: '))
y = int(input('y position: '))
a = - math.radians(int(input('angle to add: ')))
new_x = math.cos(a)*x - math.sin(a)*y
new_y = math.sin(a)*x + math.cos(a)*y
print(f'new point: {new_x} {new_y}')