forked from auguryerc/ReadStagYY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YYtoMap2.m
51 lines (38 loc) · 1.52 KB
/
YYtoMap2.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
function [amap,theta,phi] = YYtoMap2(ayy)
% this version does not require the theta and phi arguments, and expects
% ayy to be 3-dimensional ayy(itheta,iphi,iblock)
nth=size(ayy,1);
nph=nth*3;
% load yin grid directly into map
nthmap=2*nth; nphmap=(4*nph)/3;
amap = zeros(nthmap,nphmap);
for i=1:nthmap
theta1=pi*(i-0.5)/nthmap; % range 0 to pi
for j=1:nphmap
phi1=2*pi*(j-0.5)/nphmap-pi; % range -pi to +pi
theta2=acos(sin(theta1)*sin(phi1));
phi2=atan2(cos(theta1),-sin(theta1)*cos(phi1));
ongrid1 = (theta1>0.25*pi) && (theta1<0.75*pi) && (abs(phi1)<0.75*pi);
ongrid2 = (theta2>0.25*pi) && (theta2<0.75*pi) && (abs(phi2)<0.75*pi);
if ongrid1 && ongrid2
if abs(phi1)<abs(phi2)
ongrid2 = 0;
else
ongrid1 = 0;
end
end
if ongrid1
% in yin grid
itheta=round(0.5+nth*(theta1-0.25*pi)/(0.5*pi)); itheta=min(itheta,nth);
iphi=round(0.5+nph*(phi1+0.75*pi)/(1.5*pi))+1; iphi=min(iphi,nph);
amap(i,j) = ayy(itheta,iphi,1);
elseif ongrid2
% in yang grid
itheta=round(0.5+nth*(theta2-0.25*pi)/(0.5*pi)); itheta=min(itheta,nth);
iphi=round(0.5+nph*(phi2+0.75*pi)/(1.5*pi))+1; iphi=min(iphi,nph);
amap(i,j) = ayy(itheta,iphi,2);
end
theta(i) = theta1;
phi(j) = phi1;
end
end