-
Notifications
You must be signed in to change notification settings - Fork 0
/
sphvecs.m
executable file
·65 lines (49 loc) · 1.32 KB
/
sphvecs.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function v = sphvecs(isz)
% FUNCTION norms = sphvecs(isz)
% Returns the surface normals in our spherical map around the camera.
%
% Our spherical coordinate system looks down the -z axis. Azimuth looks
% left/right, Inclination looks up/down.
%
% Azimuth
% th = 0 : -z axis (when phi = 0)
% th = pi/2 : +x axis (when phi = 0)
% th = -pi/2 : -x axis (when phi = 0)
% th = pi : +z axis (when phi = 0)
%
% Elevation
% ph = 0 : -z axis (when th = 0)
% ph = pi/2 : +y axis (when th = 0)
% ph = -pi/2 : -y axis (when th = 0)
%
%
% PARAMETERS
% isz : The size of the environment map [M N].
%
% RETURNS
% varargout : Returns either
% norms : A MxNx3 matrix specifying x,y,z
% OR
% [x y z] : Each individual plane
%
% SEE ALSO: sph2vec, vec2sph, sphareas, sphmaprange
%
% Make the map
[th ph] = sphmaprange(isz);
[tm pm] = meshgrid(th, ph);
% Vectors
v = sph2vec2([tm(:)'; pm(:)']);
x = reshape(v(1,:), isz);
y = reshape(v(2,:), isz);
z = reshape(v(3,:), isz);
% Return norms to user
if nargout == 1
varargout{1} = cat(3, x, y, z);
elseif nargout == 3
varargout{1} = x;
varargout{2} = y;
varargout{3} = z;
else
error('Can only output 1 or 3 return values.')
end
end