坐标之间的Python转换 [英] Python conversion between coordinates
本文介绍了坐标之间的Python转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有不同坐标系之间的转换函数?
Are there functions for conversion between different coordinate systems?
例如,Matlab 有 [rho,phi] = car2pol(x,y)
用于从笛卡尔坐标到极坐标的转换.似乎它应该在 numpy 或 scipy 中.
For example, Matlab has [rho,phi] = cart2pol(x,y)
for conversion from cartesian to polar coordinates. Seems like it should be in numpy or scipy.
推荐答案
使用 numpy,您可以定义以下内容:
Using numpy, you can define the following:
import numpy as np
def cart2pol(x, y):
rho = np.sqrt(x**2 + y**2)
phi = np.arctan2(y, x)
return(rho, phi)
def pol2cart(rho, phi):
x = rho * np.cos(phi)
y = rho * np.sin(phi)
return(x, y)
这篇关于坐标之间的Python转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文