# Problem in coordinate conversion

조회 수: 4 (최근 30일)
Rajbir Singh 2019년 6월 13일
댓글: Rik 2019년 6월 13일
I am trying to convert coordinate from cartesian to polar and polar to cartesian.
Results are fine in case of polar to cartesian ( using [x, y, z] = pol2cart(th, rho, z) ). But when i tried to convert cartesian to polar (using [th, rho, z] = cart2pol(x, y, z) ), it doest not give desired results. As the angle is decreasing after 180.
Data Used:
x y z
-14.878048 1.563746 -327.42304
-14.903073 1.30385 -329.891304
-14.923558 1.043557 -331.798206
-14.939498 0.782946 -333.19258
-14.950887 0.522096 -334.124542
-14.957722 0.261088 -334.64534
-14.96 0 -334.807194
-14.957722 -0.261088 -334.663137
-14.950887 -0.522096 -334.266858
-14.939498 -0.782946 -333.672529
-14.923558 -1.043557 -332.934651
Wrong Results:
th rh z
174 14.9600004626611 -327.423040000000
175 14.9600003230558 -329.891304000000
176 14.9599998192384 -331.798206000000
177 14.9600001648035 -333.192580000000
178 14.9600002112294 -334.124542000000
179 14.9600004803819 -334.645340000000
180 14.9600000000000 -334.807194000000
-179 14.9600004803819 -334.663137000000
-178 14.9600002112294 -334.266858000000
-177 14.9600001648035 -333.672529000000
-176 14.9599998192384 -332.934651000000
Desired Results:
th rh z
174 14.96 -327.42304
175 14.96 -329.891304
176 14.96 -331.798206
177 14.96 -333.19258
178 14.96 -334.124542
179 14.96 -334.64534
180 14.96 -334.807194
181 14.96 -334.663137
182 14.96 -334.266858
183 14.96 -333.672529
184 14.96 -332.934651
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Rajbir Singh 2019년 6월 13일
Thank you Joel, it works.
Rik 2019년 6월 13일

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Rik 2019년 6월 13일
This behavior is as documented. The result is in the [-pi pi] radians range. If you want to have your angles in the range [0 360] degrees, you can use the mod function:
mod(-179,360)
%returns 181

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by