-
Notifications
You must be signed in to change notification settings - Fork 2
/
loc_view.m
46 lines (43 loc) · 2.14 KB
/
loc_view.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
function loc_view(th, phi)
%function loc_view(theta, phi)
%this function orients the brain and always puts the lighting behind you
%theta and phi are in degrees, not radians
%make sure the brain plot is your current axis
%this function rotates the brain and lighting to the spherical angle
%inputted. it is non-standard b/c of matlab. so, phi is really "elevation" and not
%phi from standard physics coordinates. (0,0) is at the back of the brain. for example:
%loc_view(180,90) views from the top with the front downward, and
%loc_view(180,90) has the front upward, loc_view(90,0) is from the right,
%maybe i should alter it later so there is the option
%of inputting cartesian, but that can be ambiguous, for example [0 0 1] has ambiguous orientation.
%
% Copyright (C) 2009 K.J. Miller, Dept of Neurology and Neurosurgery, University Medical Center Utrecht
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
view(th,phi),
%%if you want to go the other way
% [th,phi,r]=cart2sph(view_pt(1),view_pt(1),view_pt(1)); %in radians, but "view" uses degrees with different origin
% th=360*(th+pi/2)/(2*pi);
% phi=360*phi/(pi)
view_pt=[cosd(th-90)*cosd(phi) sind(th-90)*cosd(phi) sind(phi)];
%in order to change the direction of the light:
a=get(gca,'Children');
for i=1:length(a)
b=get(a(i));
if strcmp(b.Type,'light') %find the correct child (the one that is the light)
%object for light is the 2nd element, then use a
set(a(i),'Position',view_pt)
%or something
end
end