Polar to cartesian conversion problem

4 ビュー (過去 30 日間)
Michael Elman
Michael Elman 2020 年 8 月 31 日
コメント済み: Michael Elman 2020 年 8 月 31 日
Hey,
I need to convert two vectors in polar coordinates (rho,phi) to cartesian coordinates, but something goes wrong because if I convert it back (from cartesian to polar) I don't get the same results ().
phi=linspace(0,2*pi,N);
rho=linspace(0,R_a,N);
[x,y] = pol2cart(phi,ro);
[theta2,rho2] = cart2pol(x,y);
Thanks in advance.

採用された回答

Stephen23
Stephen23 2020 年 8 月 31 日
編集済み: Stephen23 2020 年 8 月 31 日
"but something goes wrong because if I convert it back (from cartesian to polar) I don't get the same results"
Nothing goes wrong, you just have two different representations of the same angle.
Your input angles are given over the range 0 .. 2*pi, but cart2pol documentation clearly states that its ouput "...value of the angle is in the range [-pi pi]", so we would certainly not expect to have the same values.
You can convert to 0..2*pi using mod:
theta2 = mod(theta2,2*pi);
Note that due to floating point error we would still not expect those values to be exactly the same, but close enough.
  1 件のコメント
Michael Elman
Michael Elman 2020 年 8 月 31 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by