How to plot concentric hexagons
Mostra commenti meno recenti
I tried to use the code below to plot 2 concentric hexagons but I am having problems with their width and more problems when I try to increase the hexagons to three. Any help will be appreciated.
clc
clear all
scale=4;
scale0=5;
L = linspace(0,2.*pi,7);
% N_sides = 6;
% L=(1/(N_sides*2):1/N_sides:1)';
% L=L*2*pi;
% L1=L;
xv = cos(L)'; xz = cos(L)';
yv = sin(L)'; yz = sin(L)';
xv=scale*[xv; xv(1)]; xz =scale0*[xz; xz(1)];
yv=scale*[yv; yv(1)]; yz =scale0*[yz; yz(1)];
% xv = [xv ; xv(1)]; yv = [yv ; yv(1)];
% xz = [xz ; xz(1)]; yz = [yz ; yz(1)];
x = rand(50); y = rand(50);
v = rand(20); w = rand(20);
in = inpolygon(x,y,xv,yv);
inz = inpolygon(v,w,xz,yz);
figure
plot(xv,yv,x(in),y(in),'r+',x(~in),y(~in),'bo')
hold
plot(xz,yz,v(inz),w(inz),'b+',v(~inz),w(~inz),'ro')
A=numel(y(in)), b=numel (x(~in))
C=numel(v(inz)), d=numel (w(~inz))
Risposta accettata
Più risposte (4)
Chad Greene
il 3 Mag 2015
If the problem is with the aspect ratio, try ending with
axis equal
circles(1,0,1:10,'vertices',6,'facecolor','none')
which places 10 concentric 6-point 'circles' centered at (1,0).

% function [Point] = HexCorner(x,y,side,ii)
angle_deg = 60*ii + 30;
angle_rad = angle_deg*(pi/180);
Point = [x + side*cos(angle_rad),y + side*sin(angle_rad)];
end
x = 0;
y = 0;
side = [2:2:12];
for ii = 1:6
points1(ii,:)= HexCorner(x,y,side(1),ii);
points2(ii,:)= HexCorner(x,y,side(2),ii);
points3(ii,:)= HexCorner(x,y,side(3),ii);
points4(ii,:)= HexCorner(x,y,side(4),ii);
points5(ii,:)= HexCorner(x,y,side(5),ii);
points6(ii,:)= HexCorner(x,y,side(6),ii);
end
hold on
grid on
box on
set(gca,'linewidth',3)
patch(points6(:,1),points6(:,2),'b')
patch(points5(:,1),points5(:,2),'g')
patch(points4(:,1),points4(:,2),'y')
patch(points3(:,1),points3(:,2),'r')
patch(points2(:,1),points2(:,2),'m')
patch(points1(:,1),points1(:,2),'w')

amine ouamri
il 30 Ott 2016
0 voti
I could draw one hexagon, but I can not unscrew the hexagon has three sectors of 120 ° (degrees). Any help would be appreciated.
3 Commenti
Image Analyst
il 30 Ott 2016
What does "unscrew" mean in this context?
amine ouamri
il 3 Nov 2016
Good morning, Is having three sectors (tri-sectoral)
shivangi mahajan
il 20 Mag 2020
hello mam/ sir,
i want to ask that i have made hexagonal so that how i will make sectros in that plss give me the idea about this.
Steven Lord
il 20 Mag 2020
You can create a "stack" of concentric hexagons using polyshape.
clear X
for R = 6:-1:1
X(R) = nsidedpoly(6, 'Center', [1 2], 'Radius', R);
end
To visualize them, just plot the X vector.
h = plot(X);
You'll note that all the hexagons but the largest appear a bit muted. You can bring one of the hexagons to the "front" or "top" of the picture using uistack.
uistack(h(3), 'top')
Or if you want to see them from smallest to largest just bring each one, starting with the largest, to the top. [The second largest will be displayed "on top of" the largest, the third largest "on top of" the largest and second largest, etc.]
for k = 6:-1:1
uistack(h(k), 'top')
end
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

