Generating an Array of Hexagonal Shape Pattern

21 ビュー (過去 30 日間)
Pranjal Pathak
Pranjal Pathak 2013 年 10 月 9 日
コメント済み: Mantas Pastolis 2019 年 3 月 26 日
Hi,
Here I have added a simple code, modifying my previous post (sorry for my repost, as I am trying to make my question much more understandable). The following code generates an array of values (i.e. H matrix here) having a dimension of 256x256 which is a square matrix (pattern looks like some black and white strips). I would like to modify this square matrix into a regular hexagonal shape through Matlab code. I have no idea how to do this,so can anyone plese help me in this regard?
Code:
mx=5;
my=10;
[x, y]=meshgrid(-1:2/255:+1, -1:2/255:+1);
H=(cos((x*pi*mx)+(y*pi*my)))>0;
figure(1)
imagesc(H); colormap gray; axis image; axis off
  1 件のコメント
daniel
daniel 2015 年 6 月 16 日
this is a nice list of resources that may help you, I know this is an old post but, if you are still interested these links are quite helpful.

サインインしてコメントする。

回答 (1 件)

Bharat
Bharat 2017 年 1 月 6 日
I used patch to create a hexagonal grid.
% MWE %
l=10;
b=10;
C=rand(l,b);
xhex=[0 1 2 2 1 0]; % x-coordinates of the vertices
yhex=[2 3 2 1 0 1]; % y-coordinates of the vertices
for i=1:b
j=i-1;
for k=1:l
m=k-1;
patch((xhex+mod(k,2))+2*j,yhex+2*m,C(k,i)) % make a hexagon at [2i,2j]
hold on
end
end
axis equal
Note that this code will generate hexagons at [2i,2j] co-ordinates. You can rescale the axis (TickLabels) or rescale the vertices of the hexagon. The mod(k,2) is used to shift the hexagons by 1 in alternate rows so that they fit. I have used a random matrix. You can simply change the matrix C to your data and plot the grid accordingly.
  3 件のコメント
Sim Mah
Sim Mah 2018 年 2 月 7 日
I think they are not hexagon. The distances between the center and the corners are not constant.
Mantas Pastolis
Mantas Pastolis 2019 年 3 月 26 日
Sim Mah, they are hexagon, just not regular hexagons.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by