Converting from Cartesian to Spherical matlab?

允我心安 提交于 2019-12-08 12:20:44

问题


I'm getting confused with the variety of names for angles in Spherical Coordinates. According to Matlab documentation that "azimuth and elevation are angular displacements in radians. azimuth is the counterclockwise angle in the x-y plane measured from the positive x-axis. elevation is the elevation angle from the x-y plane. r is the distance from the origin to a point."

Ok, I will call azimuth angle as Theta and elevation angle as Phi. Now, I want to build a function that convert Cartesian to Spherical. This is what I did

function [y] = my_car2sph(x)
    d = sqrt(x(1)^2 + x(2)^2 + x(3)^2);
  Phi = acos(x(3)/d);   % elevation angle 
Theta = atan2(x(2),x(1)); % azimuth
y = [d; Theta; Phi];

Now, the output of this function

>> my_car2sph([1; 1; 1])

ans =

    1.7321   <--- d
    0.7854   <--- Theta (azimuth)
    0.9553   <--- Phi (elevation)

Now, if I use the Matlab's function, this is what I'm getting

>> [azimuth,elevation,r] = cart2sph(1,1,1)

azimuth =

    0.7854


elevation =

    0.6155


r =

    1.7321

>> 

Why the elevation angle (Phi) is not the same?


回答1:


your definition of the angle Phi defines it with respect to the vertically up direction, so it varies from 0 to 180 degrees (called Colatitude). Matlab measures that vertical angle from x-y plane, so it varies from -90 to +90 degrees (Latitude). For these sort of applications, I would suggest using degrees not radians to not get confused. So if you do Phi = asin(x(3)/d), you get the same result as Matlab.



来源:https://stackoverflow.com/questions/21214098/converting-from-cartesian-to-spherical-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!