首页 > 解决方案 > 添加角度后计算位置

问题描述

我正在尝试制作一个类似计算器的程序,它有一个特定的起点,我想在画布上取一个点(我得到这个点的 x 和 y)。现在,我想从starting_point角度上添加 30 并计算画布上的点(就像一个圆圈,只是改变它的位置)。

我没有任何关于它的代码。

我知道在数学中我必须考虑一个圆并计算它在圆上的位置,但我不确定如何在编程中做到这一点。我希望你能告诉我如何用最好的 python 或其他语言来做这件事。

标签: python-3.xmathcoordinatesangle

解决方案


这是一个示例代码:

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}')

推荐阅读