-
Notifications
You must be signed in to change notification settings - Fork 180
/
plotS2Grid.m
70 lines (55 loc) · 1.92 KB
/
plotS2Grid.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function v = plotS2Grid(varargin)
% create a regular S2Grid for plotting
%
% Syntax
% plotS2Grid('resolution',[5*degree 2.5*degree])
%
% Options
% resolution - resolution in polar and azimthal direction
% hemisphere - 'lower', 'uper', 'complete', 'sphere', 'identified'
% minRho - starting rho angle (default 0)
% maxRho - maximum rho angle (default 2*pi)
% minTheta - starting theta angle (default 0)
% maxTheta - maximum theta angle (default pi)
%
% Flags
% antipodal - include <VectorsAxes.html antipodal symmetry>
% restrict2MinMax - restrict margins to min / max
%
% See also
% equispacedS2Grid regularS2Grid
% get spherical region
sR = extractSphericalRegion(varargin{:});
% get resolution
res = get_option(varargin,'resolution',1*degree);
[rhoMin,rhoMax] = rhoRange(sR);
rho = linspace(rhoMin(1),rhoMax(1),round(1+(rhoMax(1)-rhoMin(1))/res));
for i = 2:length(rhoMin)
rho = [rho,nan,linspace(rhoMin(i),rhoMax(i),round(1+(rhoMax(i)-rhoMin(i))/res))]; %#ok<AGROW>
end
[thetaMin,thetaMax] = thetaRange(sR,rho);
% remove values out of region
ind = (thetaMax > 1e-5) & (thetaMin < pi - 1e-5);
ind(end) = ind(end-1); ind(1) = ind(2);
% we should put some nans to seperate regions
rho(diff(ind) == 1) = nan;
ind(diff(ind) == 1) = true;
rho(~ind) = []; thetaMin(~ind) = []; thetaMax(~ind) = [];
if isempty(rho)
v = vector3d;
theta = [];
else
% generate grid
dtheta = thetaMax - thetaMin;
% ensure an odd number of points to have some points at the equator
ntheta = max(3,2*round(max(dtheta./res./2))+1);
theta = linspace(0,1,ntheta).' * dtheta + repmat(thetaMin,ntheta,1);
rho = repmat(rho,ntheta,1);
v = vector3d('theta',theta,'rho',rho);
end
v = v.setOption('plot',true,'resolution',res,'region',sR,'theta',theta,'rho',rho);
% the above procdure does not work so well if we have a full sphere
% and the theta region is not connected
% thatswhy we have to check once again
v(~sR.checkInside(v)) = nan;
end