MATLAB趣味绘图-内接正六边形旋转
观察一下内部的正六边形大概在外部的正六边形边的四等分点的位置,通过数学平面几何知识可得边和角度的迭代关系式为:
a
n
=
13
4
a
n
−
1
θ
n
=
θ
n
−
1
+
arctan
3
6
a_n = \frac{\sqrt{13}}{4} a_{n-1} \\ \theta_n = \theta_{n-1}+\arctan{\frac{\sqrt3}{6}}
an=413an−1θn=θn−1+arctan63
然后用MATLAB绘制如下。
main.m
a = 1;
t = pi/6;
n = 32;
hold on
set(gcf,'position',[600 100 800 800])
axis square off
axis([-1 1 -1 1])
c = [1 1 1];
for i = 1:n
hexagon(a,t,c)
a = sqrt(13)/4*a;
t = t+atan(sqrt(3)/6);
c = c*0.97;
pause(0.1)
end
hexagon.m
function hexagon(a,t,c)
theta = t:pi/3:t+2*pi;
x = a*cos(theta);
y = a*sin(theta);
x(end+1) = x(1);
y(end+1) = y(1);
%patch(x,y,'w','LineWidth',2)
for i = 1:6
plot(x(i:i+1),y(i:i+1),'r','linewidth',2)
pause(0.05)
end
fill(x,y,c)
end