java俄罗斯方块旋转_Java Tetris – 使用旋转矩阵的旋转

我正在用

Java构建俄罗斯方块,我正在尝试使用线性代数来旋转由4个瓦片组成的片段.

我的朋友在解释这样做的方法是:

他说:

“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 0)(1 0,1 1)(2-1,2 0)=

旋转坐标:(0,3)(1,2)(1,2)(1,2)

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

有什么想法?

谢谢!

最佳答案 你有两个错误.

错误1:

你做这个数学:

(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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值