Problem in coordinate conversion
이전 댓글 표시
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
Joel Handy
2019년 6월 13일
Those angles appear to match up. Sounds like you want your ansers to be in the range 0 to 360 (0 to 2PI) while the cart2pol function outputs in the range of -180 to 180 [-pi to pi].
You'll have to do a little converserion for yourself to get values in the range you want them in. Something like ...
th(th<0) = 360 + th(th<0);
Rajbir Singh
2019년 6월 13일
Rik
2019년 6월 13일
@Joel please put your answer in the answer section. Then Rajbir can accept whichever answer works best for them.
답변 (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
카테고리
도움말 센터 및 File Exchange에서 Language Fundamentals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!