forked from xiaoli1368/Microphone-sound-source-localization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_xyzToRtheta.m
32 lines (30 loc) · 1020 Bytes
/
my_xyzToRtheta.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function result = my_xyzToRtheta(x,y,z)
% Note:
% This function is used to translate the cartesian coordinates to the
% spherical coordinates.
% Usage:
% result = my_xyzToRtheta(x,y,z)
% Input arguments:
% x : the x-coordinate
% y : the y-coordinate
% z : the z-coordinate
% Output arguments:
% result : the output spherical coordinates [r, theta, phi]
% For example:
% x = 0.7071;
% y = 0.7071;
% z = 0.0000;
% result = [1,90,45];
% 说明:
% 本函数用来实现将直角坐标转换为球坐标
% 输入:直角坐标 x,y,z
% 输出:极径,俯仰角,方位角 r,theta,phi(角度值)
% 注意:当极径为零时,角度可以有多个值,这里仅输出为零
% --------------------------------------------------------------
% 开始转换
r = sqrt(x^2+y^2+z^2); % 计算极径
theta = acos(z/r)/pi*180; % 计算俯仰角
phi = atan(y/x)/pi*180; % 计算方位角
result = [r,theta,phi]; % 输出结果
result(isnan(result)) = 0; % 用来处理一些特殊情况
end