Problem in coordinate conversion
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
  Rik
      
      
 il 13 Giu 2019
				@Joel please put your answer in the answer section. Then Rajbir can accept whichever answer works best for them.
Risposte (1)
  Rik
      
      
 il 13 Giu 2019
        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
0 Commenti
Vedere anche
Categorie
				Scopri di più su Language Fundamentals in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!