2016-11-26 58 views
0

所以我需要能够在保留原始数组的同时获得旋转数组的特定部分。虚拟阵列旋转

我有什么不能如何应用,我不知道是因为旋转还是其他原因。

什么我对旋转(在伪代码):

get(x, y, rot%4): 
    rot == 1 then arr[height - 1 - y, x] 
    rot == 2 then arr[width - 1 - x, height - 1- y] 
    rot == 3 then (rot 2, rot 1) 
    else arr[x, y] 

我99%肯定旋转180度(2)按预期工作,但我敢肯定,我搞乱向上90度,延长270度。

回答

0

最终我想出了一些正确的东西。除了这个,我的系统的每个部分都在工作,这基本上是最简单的部分。

get(x, y, rot%4): 
    rot == 2 || rot == 3 then 
    y = height - 1 - y 
    x = width - 1 - x 
    rot == 1 || rot == 3 then 
    tmp = y 
    y = x 
    x = height - 1 - tmp 
    return arr[x, y] 

主要优势,这样在转动整个数组是,如果你只需要从阵列中,如用2D“viewportals”的旋转版本抢值的微小的量,或刚刚开始一个特定的行/列/对角线,或者那种类型的东西。