三阶魔方绘制-动态变化

魔方绘制

魔方绘制可以参考链接: 【手把手制作三阶魔方模拟器】用MATLAB绘制一个三阶魔方和 【手把手制作三阶魔方模拟器】用MATLAB让你的魔方动起来。
可以达到的效果为:

可以看到魔方没有动态变化,只是颜色的变化。
在旋转公式函数中,90度为一次循环,改变为单次循环为10度,循环9次,便可以将过程动态展现出来。

alpha = -pi/2*alpha;
beta = -pi/2*beta;
gamma = -pi/2*gamma;

变化后为:

function R = getRotateMatrix(alpha,beta,gamma)
% alpha,beta,gamma 为1或-1,分别表示顺时针转和逆时针转alpha = -pi/18*alpha;  %-pi/2*alpha;
beta = -pi/18*beta;  %-pi/2*beta;
gamma = -pi/18*gamma; %-pi/2*gamma;Rx = [1,0,0;0,cos(alpha),-sin(alpha);0,sin(alpha),cos(alpha)];
Ry = [cos(beta),0,sin(beta);0,1,0;-sin(beta),0,cos(beta)];
Rz = [cos(gamma),-sin(gamma),0;sin(gamma),cos(gamma),0;0,0,1];
R = (Rx*Ry*Rz)';end

测试函数

由于每次转动角度为10度,因此,主函数即测试函数需要对每次每一个操作循环9次。

操作代码部分:

H = initshowcube(axisBlock, cornerBlock, edgeBlock, ...blockVertices, blockFace, color, colorAlpha);%% 操作
% 设置操作
optList = 'RUUR,U,RUR,U,RU,R,';
% 转为编号
[optIdx,optNum] = getOptIdx(optList);
% 循环转动
for k = 1:optNumfor i = 1:9   % 执行[blockIdx, axisBlock, cornerBlock, edgeBlock] = operation(optIdx(k), blockIdx, axisBlock, cornerBlock, edgeBlock);% 显示showcube(H, axisBlock, cornerBlock, edgeBlock, ...blockVertices, blockFace, color, colorAlpha)pause(0.1)endend

在每次操纵的大循环中加入9次小循环,并显示9次就可以实现了。

中心块转动

但是,这个时候发现一个问题,在旋转过程中,魔方中心块不旋转,只有角块和棱块变化,主要原因是魔方各操作时,没有将中心块位置变化写出,导致变化过程不包含中心块,主要对function [blockIdx, axisBlock, concerBlock, edgeBlock] = operation(opt, blockIdx, axisBlock, concerBlock, edgeBlock) 前12种情况函数进行修改,如下:

function [blockIdx, axisBlock, cornerBlock, edgeBlock] = operation(opt, ...blockIdx, axisBlock, cornerBlock, edgeBlock)switch optcase 1 % FR = getRotateMatrix(1,0,0);for n = blockIdx.axisIdx(2)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([1,2,6,5])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([1,5,9,8])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([1,2,6,5]) = blockIdx.cornerIdx([2,6,5,1]) ;blockIdx.edgeIdx([1,5,9,8]) = blockIdx.edgeIdx([5,9,8,1]);case -1 % F'R = getRotateMatrix(-1,0,0);for n = blockIdx.axisIdx(2)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([1,2,6,5])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([1,5,9,8])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([1,2,6,5]) = blockIdx.cornerIdx([5,1,2,6]) ;blockIdx.edgeIdx([1,5,9,8]) = blockIdx.edgeIdx([8,1,5,9]);case 2 % RR = getRotateMatrix(0,1,0);for n = blockIdx.axisIdx(3)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([2,3,7,6])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([2,6,10,5])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([2,3,7,6]) = blockIdx.cornerIdx([3,7,6,2]) ;blockIdx.edgeIdx([2,6,10,5]) = blockIdx.edgeIdx([6,10,5,2]);case -2 % R'R = getRotateMatrix(0,-1,0);for n = blockIdx.axisIdx(3)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([2,3,7,6])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([2,6,10,5])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([2,3,7,6]) = blockIdx.cornerIdx([6,2,3,7]) ;blockIdx.edgeIdx([2,6,10,5]) = blockIdx.edgeIdx([5,2,6,10]);case 3 % UR = getRotateMatrix(0,0,1);for n = blockIdx.axisIdx(6)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([5,6,7,8])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([9,10,11,12])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([5,6,7,8]) = blockIdx.cornerIdx([6,7,8,5]) ;blockIdx.edgeIdx([9,10,11,12]) = blockIdx.edgeIdx([10,11,12,9]);case -3 % U'R = getRotateMatrix(0,0,-1);for n = blockIdx.axisIdx(6)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([5,6,7,8])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([9,10,11,12])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([5,6,7,8]) = blockIdx.cornerIdx([8,5,6,7]) ;blockIdx.edgeIdx([9,10,11,12]) = blockIdx.edgeIdx([12,9,10,11]);case 4 % BR = getRotateMatrix(-1,0,0);for n = blockIdx.axisIdx(4)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([3,4,8,7])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([3,7,11,6])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([3,4,8,7]) = blockIdx.cornerIdx([4,8,7,3]) ;blockIdx.edgeIdx([3,7,11,6]) = blockIdx.edgeIdx([7,11,6,3]);case -4 % B'R = getRotateMatrix(1,0,0);for n = blockIdx.axisIdx(4)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([3,4,8,7])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([3,7,11,6])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([3,4,8,7]) = blockIdx.cornerIdx([7,3,4,8]) ;blockIdx.edgeIdx([3,7,11,6]) = blockIdx.edgeIdx([6,3,7,11]);case 5 % LR = getRotateMatrix(0,-1,0);for n = blockIdx.axisIdx(5)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([1,5,8,4])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([4,8,12,7])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([1,5,8,4]) = blockIdx.cornerIdx([5,8,4,1]) ;blockIdx.edgeIdx([4,8,12,7]) = blockIdx.edgeIdx([8,12,7,4]);case -5 % L'R = getRotateMatrix(0,1,0);for n = blockIdx.axisIdx(5)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([1,5,8,4])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([4,8,12,7])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([1,5,8,4]) = blockIdx.cornerIdx([4,1,5,8]) ;blockIdx.edgeIdx([4,8,12,7]) = blockIdx.edgeIdx([7,4,8,12]);case 6 % DR = getRotateMatrix(0,0,-1);for n = blockIdx.axisIdx(1)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([1,2,3,4])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([1,2,3,4])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([1,2,3,4]) = blockIdx.cornerIdx([4,1,2,3]) ;blockIdx.edgeIdx([1,2,3,4]) = blockIdx.edgeIdx([4,1,2,3]);case -6 % D'R = getRotateMatrix(0,0,1);for n = blockIdx.axisIdx(1)axisBlock{n}.RotateMatrix = axisBlock{n}.RotateMatrix*R;endfor n = blockIdx.cornerIdx([1,2,3,4])cornerBlock{n}.RotateMatrix = cornerBlock{n}.RotateMatrix*R;endfor n = blockIdx.edgeIdx([1,2,3,4])edgeBlock{n}.RotateMatrix = edgeBlock{n}.RotateMatrix*R;endblockIdx.cornerIdx([1,2,3,4]) = blockIdx.cornerIdx([2,3,4,1]) ;blockIdx.edgeIdx([1,2,3,4]) = blockIdx.edgeIdx([2,3,4,1]);

修改后执行便可以得到可以动态运动的魔方了。

matlab 绘制三阶魔方-动态变化相关推荐

  1. 狼羊白菜过河matlab编程,matlab绘制农夫过河动态图

    仿真秀平台一直有做针对于matlab入门的公开课,算法工匠带你学MATLAB基础课程,入门一段时间后我们就可以用 matlab做一下有意思的事比如说画个动态图: 是不是很神奇,使用好matlab动态绘 ...

  2. MATLAB绘制主函数动态图,matlab绘制动态图

    mathematica绘制动态图,"绘图之王"争霸赛--Excel才是绘图王道,matlab绘制动态图,动态三维图绘制 matlab动态图画法_数学_自然科学_专业资料.Matla ...

  3. 利用Matlab绘制弹簧—阻尼动态振动模型

    前言 Matlab是进行数值计算的重要工具,更是科学研究中非常强大的辅助工具,其不仅在数值计算.数据绘图.科学仿真等方面广泛应用,而且在科研中一些动态模型的绘制也可以用其实现.本文就以弹簧-阻尼振动模 ...

  4. MATLAB对三阶魔方建模并进行旋转操作

    对于魔方的表示: 先看一串天书般的字母:UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR 这种表示法是由一个叫Mi ...

  5. 三阶魔方有多少种状态

    魔方有 3 种不同的方块,分别为角块(8 个,每个角块有三种颜色),棱块(12 个,每个棱块有两种颜色)与中心块(6 个,每个中心块有一种颜色). 魔方总共有 6 个面,每个面的颜色不一样,每个面被分 ...

  6. 三阶魔方自动求解及动态可视化matlab代码

    三阶魔方自动求解及动态可视化matlab代码 思路与步骤 总结 思考 参考链接 源代码 第一次写博客,想总结分享下以前做过的一些有趣的东西,目的是为了回望过去与展望未来,同时为了提高自己的写作表达能力 ...

  7. 【手把手制作三阶魔方模拟器】用MATLAB绘制一个一阶魔方

    [手把手制作三阶魔方模拟器]用MATLAB绘制一个一阶魔方 在三维空间绘制一个正方形 在三维空间绘制一个正六面体 其他 by 今天不飞了 有一个酷爱魔方的朋友,托我给他定制一个专门用于"训练 ...

  8. 【手把手制作三阶魔方模拟器】用MATLAB让你的魔方动起来

    [手把手制作三阶魔方模拟器]用MATLAB让你的魔方动起来 1 定义魔方初始状态 2 操作模块 2.1 全操作定义 2.2 旋转公式小函数 2.3操作识别 3 显示模块 3.1 初始化 3.2 显示操 ...

  9. 基于MATLAB GUI的魔方三维动态还原仿真程序

    软件MATLAB R2019A 1.程序介绍 使用MATLAB GUI功能设计制作一个魔方三维动态还原仿真程序,点击魔方旋转按钮U\D\F\B\L\R旋转方面相应面,逆\顺时针按钮切换旋转方向,文字编 ...

最新文章

  1. python deque双端队列的神奇用法
  2. java fx alert_javaFx:使用弹出对话框 Alert
  3. golang适合做什么_这年头中年女人适合做什么兼职
  4. 低差异序列:范德科皮特序列(Van der Corput sequence)
  5. bootstrap的栅格系统和响应式工具
  6. LeetCode 148. 排序链表(归并排序、快速排序)
  7. 怎么成为开源贡献者_成为负责任的开源用户
  8. matlab开关电源仿真软件,开关电源仿真设计软件选择
  9. 卡巴斯基密码管理器新版面世,再也不必担心账户安全
  10. 乐优商城(四十八)评论微服务(一)
  11. 什 么 是 勒 索 病 毒 ?
  12. 北京大学计算机系张润楠,▶拜泉县第一中学2019年高考喜报
  13. css中clip属性的使用
  14. Spring Cloud微服务简介
  15. 如何成为优秀的数据人经验分享
  16. 服务器系统进不了路由器,Win7输入192.168.0.1打不开路由器管理界面的解决方法
  17. Pytorch学习笔记——fan_in和fan_out
  18. 计蒜客-幼儿园买玩具(java实现)
  19. Docker搭建公司内部私有云平台 -- Gitlab
  20. Jabber简单工作过程(转)

热门文章

  1. 用借款方实际付出的手续费(或利息)计算真实的手续费率(或利率)
  2. C++将小数化成分数
  3. pandas实现分类汇总--小计,总计
  4. centos打显卡驱动命令_centos7系统,显卡驱动安装教程
  5. 计算机网络设备调试员报名,工信部网络设备调试员一级高级技师、二级技师
  6. Lora、zigbee比较
  7. ccf 202012-3 带配额的文件系统(大模拟)
  8. 授信合同与贷款合同的区别
  9. 图解IFRS9 金融工具(6)ECL预期减值
  10. 移动端用户放大字体导致样式出问题