Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档 > MATLAB技术文章
MATLAB技术文章 MATLAB Technical Articles From Mathworks
 
 
主题工具 显示模式
旧 2022-12-10, 12:37   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
默认 Color Cube Meets Rubik?s Cube - Cleve Moler on Mathematics and Computing

I have made a half dozen blog posts about Rubik's Cube so far this year. And, during the MATLAB Central Mini Hack in October, I resurrected an old code about the Color Cube. Now, a combination of the two, Rubik/Color Qube, creates an elegant tool for investigating Matrices in Action.

Contents
Opening

Here is the opening screen shot of Rubik/Color Qube, one of the most elaborate MATLAB programs that I have ever written.



Rubik and Color

There are two modes, rubik and color. In rubik mode, the large cube is formed from 27 identical copies of a single small cubelet. The six cubelet faces have six different colors. Red, white and blue are visible initially. Orange, yellow and green become visible as the faces are rotated.



In color mode, the large cube is formed from 27 cubelets, each with a different solid color. Three of the corner cubelets are the primary colors in the RGB color model -- red, green and blue. Three more corners are the complementary cyan, magenta and yellow. White and black complete the list of corners.



Color Qube

All of the familiar Rubik's moves are available in color mode. Here is a screen shot after a few rotations.



Rotations

Rotation matrices defined by this Rk function are the basic mathematical tool employed by Qube. The animation provides a detailed look at the action produced by the F key, counter-clockwise rotation of the Front face. This is the y-axis, case 2 in Rk. The detail is provided by taking d = 0:3:90, so there are 30 steps of 3 degrees.

function R = Rk(axis,d) % Rk(axis,d), Rotation by d degrees about the x-, y-, or z-axis. c = cosd(d); s = sind(d); switch axis case 1, R = [ 1 0 0 0 c s 0 -s c ]; case 2, R = [ c 0 s 0 1 0 -s 0 c ]; case 3, R = [ c s 0 -s c 0 0 0 1 ]; end fmat = findobj('tag','fmat'); if ~isempty(fmat) fmat.String = mat3(R); endend

n-by-n-by-n

Qube generalizes the classic 3-by-3-by-3 Rubik's Cube to n-by-n-by-n cubes for any n.



2-by-2-by-2

The 2-by-2-by-2 cubes are good starting points for investigation of mathematical properties.





Software

Qube is available as a self-extracting MATLAB archive at this link, Qube_mzip.m.


Get the MATLAB code (requires JavaScript)

Published with MATLAB® R2022b




More...
poster 当前离线   回复时引用此帖
 

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 05:16


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.