制作魔方的对象模型
我制作了一个小算法,可以让我解决纸上的魔方问题。
我现在想实现它,但我找不到令我满意的对象表示。
我很容易就能看到一个 rubiksCube 对象,以及一个“立方体”对象,它可以通过面、角或边来实现。
但我需要它们之间的一些对象,以指定哪个位置是哪个立方体。
最终目标是我可以轻松地对其进行一些旋转。
您知道如何表示这一点吗?
非常感谢
I've made a small algo which allows me to resolve a rubik's cube on the paper.
I now want to implement it, but I can't found an object representation which satisfied me.
I easily can see a rubiksCube object, and a "cube" object, which can be implemented by a face, a corner or an edge.
But I need some objects between, to specify on which place is which cube.
The final goal is that I can easily make some rotation on it.
Do you have an idea about how to represent this?
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这篇 CodeProject 的文章看起来正是您所需要的。它也具有所有运动和解算器功能。
This CodeProject's article looks exactly what you need. It has all the movements and solvers funcs as well.
我会构建这样的东西:
立方体的中心是 (0, 0, 0),你可以想象这些点漂浮在实际的立方体上。小瓷砖被抽象为点,因此不需要定向。这样,所有正面图块的 z 坐标为 2,所有顶面图块的 y 坐标为 2,所有左面图块的 x 坐标为 -2,依此类推。
看一下旋转矩阵。旋转矩阵的美妙之处在于它们总是围绕坐标系的中心 (0, 0, 0) 旋转,当你有一堆点时(就像这里),旋转更像是圆周运动。
如果将 θ 设置为 90°(在 Rx 中),则
可以将其转换为以下方法:
您只需调用 Cube.rotateLayerX(cube.LeftLayer) 即可。
这只是一个简单的彩色点云。
你是对的,这个东西不是严格类型化的,它可以调用 Cube.rotateLayerX(Cube.TopLayer) (或其他任意的图块集合),这是没有意义的。但这样做是愚蠢的……所以不要这样做;)
I would build something like this:
The center of the cube would be (0, 0, 0) and you could imagine these points floating over the actual cube. The little tiles are abstracted to points and therefor need no orientation. This way all front face tiles have a z-coordinate of 2, all top face tiles have a y-coordinate of 2, all left face tiles have a x-coordinate of -2 and so on.
Take a look at rotation matrices. The beauty of rotation matrices is that they always rotate about the center of the coordinate system (0, 0, 0) and when you have a bunch of points(like here) the rotation is more like a circular movement.
If you set θ to 90°(in Rx) you get
Which could be translated to the following Method:
Than you only have to call
Cube.rotateLayerX(cube.LeftLayer)
.It's just a simple colored point cloud.
And you're right this thing is not strictly typed and it's possible call
Cube.rotateLayerX(Cube.TopLayer)
(or an other arbitrary collection of tiles), which makes no sense. But doing this would be stupid… so don't do it ;)用 5 x 5 x 5 颜色矩阵表示魔方,其中仅使用 6 个矩阵表面中每一个的 3 x 3 中心矩阵位置来表示颜色。
为了旋转 Rubic 立方体的边界切片,您必须旋转矩阵的两个边界切片。可以通过仅旋转一个矩阵切片来旋转中心切片。这种方法的优点是您可以执行简单的矩阵旋转,并且可以在 3D 中执行所有操作。您不必从某些平面 2D 投影重建 3D 外观。
注意:这种“夸张”的大小是必需的,因为每个矩阵单元只能存储一种颜色。将两个矩阵切片放在一起,可以存储边缘的两种颜色和角的三种颜色。
Represent Rubik's cube by a 5 x 5 x 5 matrix of colors where only the 3 x 3 center matrix positions of each of the 6 matrix surfaces are used to represent the colors.
In order to rotate a border slice of Rubic's cube, you will have to rotate two border slices of the matrix. The center slices can be rotated by rotating the one matrix slice only. The advantage of this approach is that you can perform simple matrix rotations and that you can do everthing in 3D. You don't have to reconstruct the 3D appearance from some flat 2D projection.
Note: This "exaggerated" size is required, since you can only store one color per matrix cell. Taking two matrix-slices together, allows you to store two colors for the edges and three colors for the corners.