画六边形-mat

时间:2021-05-03 07:36:33
%%
theta = linspace(0,2*pi,7);
D=2; %边长
X=1; %中心横坐标
Y=2; %中心纵坐标
plot(D*cos(theta)+X,D*sin(theta) + Y,'g-');
axis square i = 0;
while i < 3
x = 2*D*rand(1,2)-1*D;
if (abs(x(1)) + abs(x(2))/sqrt(3) ) <= D && abs(x(2)) <= D*sqrt(3)/2
i = i+1;
hold on
plot(x(1) + X, x(2) + Y,'r*');
end
end
hold off