Professional Documents
Culture Documents
htm
http://www.iterativesolutions.com/download.htm
http://www.iterativesolutions.com/download.htm
http://www.iterativesolutions.com/download.htm
I assume you mean that 1's are to lie both on and in the interior of a
hexagon. If so, let (x0,y0) be the center of the regular hexagon and d
the distance from the center to the midpoint of each of its sides. Let
the image matrix be n x m in size. Then do this:
[x,y] = meshgrid([1:m],[1:n]);
A = (abs(y-y0) <= d) & ...
(abs(sqrt(3)/2*(x-x0)+1/2*(y-y0)) <= d) & ...
(abs(sqrt(3)/2*(x-x0)-1/2*(y-y0)) <= d);
Malek
Here is the code I have been using:
% Define the unit hexagon using angles
t=(0:1/6:1)*2*pi;
% Define the center of the hexagons
alpha=[0 2*pi/3 4*pi/3];
x=cos(alpha);
y=sin(alpha);
% Values to plot on each hexagon
v=[100 200 1000];
% Define the colormap (114 is just an example)
c=colormap(jet(114));
% Map the colors to the range of values contained in the kpi vector
xmin=min(v);
xmax=max(v);
slope=113/(xmax-xmin);
offset=114-slope*xmax;
indexes=max(1,floor(offset+slope*v));
fig=figure;
set(fig,'NumberTitle','off','Name','Network Area by MBC');
hold on
grid on
box on
for i=1:3
fill(x(i)+cos(t),y(i)+sin(t),c(indexes(i),:));
end
xlabel('\bfX [m]')
ylabel('\bfY [m]')
title('\bfMap of the KPI');
colorbar(c)
hold off;
% axis([xmin xmax])
yy=[yy;y(p)];
x(p)=[];
y(p)=[];
end
at=atan2(xx,yy);
[ax,ax]=sort(at);
xx=xx(ax);
yy=yy(ax);
line(xx,yy,...
'marker','s',...
'color',[0,0,0]);
% test some data points
px=20*rand(500,1)-10;
py=20*rand(500,1)-10;
line(px,py,...
'marker','.',...
'markersize',4,...
'linestyle','none');
ix=inpolygon(px,py,xx,yy);
line(px(ix),py(ix),...
'marker','.',...
'linestyle','none',...
'color',[1,0,0]);
function heglat(nr,nc,r)
% help
% error checking
% preliminaries
v=30:60:390;
cv=r*cosd(v);
sv=r*sind(v);
% ...the center points
[x,y]=meshgrid(1:nc,1:nr);
cx=r*sqrt(3);
x=cx*x;
x(2:2:end,:)=.5*cx+x(2:2:end,:);
y=y*(r+.5*r);
for i=1:nc
for j=1:nr
line(x(j,i)+cv,y(j,i)+sv);
end
end
% axis equal;
http://www.mathworks.com/matlabcentral/newsreader/view_thread/138624