gpt4 book ai didi

Java Tetris - 使用旋转矩阵的旋转

转载 作者:搜寻专家 更新时间:2023-11-01 03:25:04 25 4
gpt4 key购买 nike

我正在用 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."

enter image description here

最后他说:

"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)

但是,看看我旋转后的形状……这是完全错误的:

enter image description here

有什么想法吗?

谢谢!

最佳答案

你有两个错误。

错误一:

你做这个数学:

(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 度旋转的原因,因为您乘以旋转矩阵两次。

错误2:

您应该将所有输出点添加到原点。

你说:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com