python-3.x - 添加角度后计算位置
问题描述
我正在尝试制作一个类似计算器的程序,它有一个特定的起点,我想在画布上取一个点(我得到这个点的 x 和 y)。现在,我想从starting_point
角度上添加 30 并计算画布上的点(就像一个圆圈,只是改变它的位置)。
我没有任何关于它的代码。
我知道在数学中我必须考虑一个圆并计算它在圆上的位置,但我不确定如何在编程中做到这一点。我希望你能告诉我如何用最好的 python 或其他语言来做这件事。
解决方案
这是一个示例代码:
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}')
推荐阅读
- mysql - 在 SQL 中显示较低和较高值的数量
- java - 在 Selenium 中使用代理
- vuejs2 - 未找到具有默认 ID 的 Vue2 组合 API Apollo 客户端
- python - 迭代 Imputer 为给定列的所有 NaN 提供相同的输出值
- kubernetes - 当配置信息丢失时,如何在 ec2 及其端口上禁用 kubernetes 和 eks
- angular - Angular 中的单元测试:Mocking RxJS observable with Jasmine
- amazon-web-services - AWS ALB 入口资源路径定义
- c# - Xaml中Border元素外的阴影状边框
- java - 线程“主”java.lang.ArrayIndexOutOfBoundsException 中的异常:99
- autodesk-forge - 所需下载速度