我想把很多点从笛卡尔坐标系转换成极坐标系
这是我的代码:
import numpy as np
x = 1
y = 1
def cart_to_pol(x, y):
rho = np.sqrt(x**2 + y**2)
phi = np.arctan2(y, x)
return(rho, phi)
print(cart_to_pol(x, y))
但我在数组中有很多点需要转换
phi = np.arctan2(y, x)*180/pi
但结果是错误的。我怎样才能修好它李>谢谢
points = [(10, 43), (10, 44), (10, 45), (10, 46), (10, 47), (10, 48), (10, 49),
(10, 50), (10, 51), (10, 52), (10, 53), (10, 54), (10, 55), (10, 56), (11, 39),
(11, 40), (11, 41), (11, 42), (11, 57), (11, 58), (11, 59), (11, 60), (12, 36),
(12, 37), (12, 38), (12, 61), (12, 62), (12, 63), (13, 33), (13, 34), (13, 35),
(13, 64), (13, 65), (13, 66), (14, 31), (14, 32), (14, 33), (14, 66), (14, 67),
(14, 68), (15, 30), (15, 31), (15, 68), (15, 69), (16, 28), (16, 29), (16, 70),
(16, 71), (17, 27), (17, 72), (18, 25), (18, 26), (18, 73), (18, 74), (19, 24)]
用复杂的数学
只需将您的中心坐标传递给
(x_c, y_c)
,或者您可以使用二维数组:我没有回答最后两个问题,但这就是如何一下子转换所有分数的方法。只需要为x,y定义一个for循环,就可以得到元组中的每个点。祝你好运
numpy可以处理矩阵或2D numpy数组
希望这能解决你的第一和第二个问题。 最后一个问题
请告诉我这是否有用
相关问题 更多 >
编程相关推荐