- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在用 Java 构建俄罗斯方 block ,并尝试使用线性代数来旋转由 4 个方 block 组成的方 block 。
我的 friend 正在解释这样做的方法是:
他说:
"To clarify, you do need to rotate each point -- that is you need to rotate one point for each Tile in a Piece. But NOT four corners for each Tile in a Piece. The origin is like if you stuck a pencil through a piece of paper and spun the pencil around.. the spot where the pencil is is the origin."
"So if you have a T on your board with Tiles at (7,9) (8,9) (9,9), (8,10) and its origin is at (8,9).."
所以我用坐标 (1, 3) (1, 2) (1, 1) (2, 2)... 原点 (1, 2) 来做这件事
然后他说:
"You translate the Tiles to be relative to the origin. That is, you treat the origin as the new (0, 0) for this rotation. That's as easy as just subtracting the origin from each coordinate, giving you (7-8, 9-9), (8-8, 9-9), (9-8, 9-9), (8-8, 10-9) or (-1, 0) (0, 0) (1, 0) (0, 1)"
从每个坐标中减去原点(1, 2)
(1-1, 3-2) (1-1, 2-2) (1-1, 1-2) (2-1, 2-2) =
(0, 1) (0, 0) (0, -1) (1, 0)
然后他说:
"Now rotate these four coordinates using the rotation matrix multiplication, like we have been talking about."
最后他说:
"Then add the origin coordinates back to each resulting coordinate, and now you have your four rotated Tile coordinates."
从上面的矩阵中,我有 (0, -1) (0, 0) (0, 1) (-1, 0)...所以我像他说的那样将它们添加到原点坐标(1-1, 3+0) (1+0, 2+0) (1+0, 1+1) (2-1, 2+0) =
旋转坐标:(0, 3) (1, 2) (1, 2) (1, 2)
但是,看看我旋转后的形状……这是完全错误的:
有什么想法吗?
谢谢!
最佳答案
你有两个错误。
你做这个数学:
(1-1, 3-2) (1-1, 2-2) (1-1, 1-2) (2-1, 2-2) =
(0, 1) (0, 0) (0, -1) (1, 0)
但是你在数学(图像)中实际写下的矩阵是:
[ -1 0 1 0 ]
[ 0 0 0 1 ]
应该是什么时候:
[ 0 0 0 1 ]
[ 1 0 -1 0 ]
这就是它看起来是 180 度旋转的原因,因为您乘以旋转矩阵两次。
您应该将所有输出点添加到原点。
你说:
From the matrix above, I have (0, -1) (0, 0) (0, 1) (-1, 0)… so I add these to the origin coordinates like he says (1-1, 3+0) (1+0, 2+0) (1+0, 1+1) (2-1, 2+0) = (0, 3) (1, 2) (1, 2) (1, 2)
但是你真正应该做的是将它们添加到 ORIGIN 中,即
(0, -1) (0, 0) (0, 1) (-1, 0) - Matrix output
(0 + 1, -1 + 2) (0 + 1, 0 + 2) (0 + 1, 1 + 2) (-1 + 1, 0 + 2) - Add back the origin (origin coordinates in bold)
(1, 1) (1, 2) (1, 3) (0, 2) - Resulting points
关于Java Tetris - 使用旋转矩阵的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16196039/
我在俄罗斯方 block 中清除行时遇到了一些奇怪的事情...... 如果我将板的宽度和高度设置为相同(10 和 10): board = new Board(10, 10, 35); 由以下因素决定
我正在构建俄罗斯方 block 并尝试实现一种方法,该方法遍历图 block 的 grid[][] 并检查每行的每一列,从底部开始,向上工作(认为它会更快检查如果我从底部开始,因为那是需要清除大多数行
我正在用 Java 构建俄罗斯方 block ,并尝试使用线性代数来旋转由 4 个方 block 组成的方 block 。 我的 friend 正在解释这样做的方法是: 他说: "To clarify
我正在用 Java 构建俄罗斯方块作为一个有趣的副项目,现在正在研究轮换。 我最初是硬编码每个旋转,这被证明是非常乏味的。 话虽如此,我当时打算使用线性代数尝试矩阵旋转,但有人在 Mathematic
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 2年前关闭。 Improve t
我正在为大学做一个俄罗斯方 block 元素。我有大部分功能可以工作,除了一个。预期流程如下: 带有加载游戏按钮的索引页 点击按钮,游戏开始播放背景音频(现在是示例音频) 暂停/玩游戏时音频也应该停止
我已经研究这个问题一段时间了,并且已经画了一个空白,所以希望得到一些帮助。 我正在使用 Python 和 Pygame 制作一个简单的俄罗斯方块克隆。问题是检测已完成行的过程有时会将克隆行添加到新 G
已锁定。这个问题及其答案是locked,因为这个问题是题外话,但具有历史意义。目前不接受新的答案或互动。 基础知识: 考虑以下四格骨牌和空的比赛 field :
我在编写俄罗斯方 block 时无法抓取当前的片段。现在,当我尝试移动一张四格骨牌时,所有四格骨牌都会移动。我已经被这个问题困扰了一段时间,我非常感谢一些帮助。下面是代码片段,我将整个代码放在 jsf
我刚刚接触 Java,我发现了这个关于创建 Java 俄罗斯方 block 游戏的好教程。 我没有导师或导师来帮助我解决这个问题 - 我一直在寻找一位导师或导师:(所以目前我正在自学 java 和 P
您好,我有一个关于在 C++ 中使用 vector 的问题,我正在研究一个通过随机运动模拟粒子在容器中运动的问题。我需要在粒子满足或不满足特定标准时添加和移除粒子,为此我发现 vector 类非常方便
我想通过按空格键来旋转元素,就像俄罗斯方 block 效果一样。但到目前为止我只能旋转一次,而且 position() 方法似乎不像使用键横向移动时那样工作。任何帮助或提示将不胜感激。这是我拥有的:
虽然我标记了这个作业,但它实际上是我自己免费做的一门类(class)。不管怎样,这门类(class)叫做“从 Nand 到俄罗斯方 block ”,我希望这里有人看过或参加过这门类(class),这样
我正在尝试将 Java 中的俄罗斯方 block 游戏作为一个有趣的业余项目。 我的游戏板是一个瓷砖网格: grid = new Tile[高度][宽度]; 在网格内,我创建一个新的 Tile 对象:
我是一名优秀的程序员,十分优秀!