• /
• # hypercube

on 19 Nov 2023
• 18
• 28
• 0
• 0
• 984
drawframe(1);
function drawframe(n)
persistent plotHdl theta XYZW rows cols
if n==1
% 批量构建四维坐标
XYZW=(abs(dec2bin(0:2^4-1))-48.5).*2;
% 找到应该链接的点的序号
IPT=tril(XYZW*XYZW');
[rows,cols]=find(IPT==2);
hold on
% 绘图句柄预定义
for i=1:length(rows)
plotHdl{i}=plot3(0,0,0,...
'Color',lines(1),'LineWidth',5,...
'Marker','o','MarkerSize',10,...
'MarkerFaceColor',lines(1));
end
% 坐标区域修饰
view(3);axis off
ax=gca;
ax.XLim=[-2.5,2.5];
ax.YLim=[-2.5,2.5];
ax.ZLim=[-2.5,2.5];
ax.Position=[-1/5,-1/5,7/5,7/5];
ax.Projection='perspective';
ax.DataAspectRatio=[1,1,1];
set(gcf,'Color',[1,1,1])
theta=linspace(pi,0,48);
end
t=n;
% 旋转矩阵
tSpinMat=[cos(theta(t)), -sin(theta(t)), 0, 0 ;
sin(theta(t)), cos(theta(t)), 0, 0 ;
0 , 0 , cos(theta(t)), -sin(theta(t));
0 , 0 , sin(theta(t)), cos(theta(t))];
tXYZW=(tSpinMat*XYZW')';
% 投影系数计算并投影
talpha=1./(2-tXYZW(:,4));
tXYZ=tXYZW(:,1:3).*talpha;
for i=1:length(rows)
plotHdl{i}.XData=[tXYZ(rows(i),1),tXYZ(cols(i),1)];
plotHdl{i}.YData=[tXYZ(rows(i),2),tXYZ(cols(i),2)];
plotHdl{i}.ZData=[tXYZ(rows(i),3),tXYZ(cols(i),3)];
end
end