TEST
2
最終更新:
eriax
表 table のセルを table(row, col) で表します。また、rows(table) を table の行数を返す関数、cols(table) を table の列数を返す関数とします。
表を時計回りに回転させたとき、
・90deg table90R(row, col) = table(rows(table) - col, row) ・180deg table180R(row, col) = table90R(rows(table90R) - col, row) = table(rows(table) - row, cols(table) - col) ※なお、rows(table90R) = cols(table), cols(table90R) = rows(table) は自明とします。 ・270deg table270R(row, col) = table180R(rows(table180R) - col, row) = table(rows(table) - (rows(table180R) - col), cols(table) - row) = table(col, cols(table) - row) ・360deg table360R(row, col) = table270R(rows(table270R) - col, row) = table(row, cols(table) - (rows(table270R) - col)) = table(row, col)
表を反時計回りに回転させたとき、
・90deg table90L(row, col) = table(col, cols(table) - row) ・180deg table180L(row, col) = table90L(col, cols(table90L) - row) = table(rows(table) - row, cols(table) - col) ・270deg table270L(row, col) = table180L(col, cols(table180L) - row) = table(rows(table) - col, cols(table) - (cols(table180L) - row)) = table(rows(table) - col, row) ・360deg table360L(row, col) = table270L(col, cols(table270L) - row) = table(rows(table) - (cols(table270L) - row), col) = table(row, col)
というわけで、ちゃんと
table360R = table360L = table(row, col) table270R = table90L = table(col, cols(table) - row) table180R = table180L = table(rows(table) - row, cols(table) - col) table90R = table270L = table(rows(table) - col, row)
になりました。
ところで、よくよく高校数学を思い出すと回転の方程式を習っていたわけで、
x' = x*cos(t) - y*sin(t) y' = x*sin(t) + y*cos(t)
今回、x は col、y は row に割り当てているので、以下の方が分かりやすいでしょう。
row' = col*sin(t) + row*cos(t) col' = col*cos(t) - row*sin(t)
そうすると、
(row', col') = ... 90deg: (col, -row) 180deg: (-row, -col) 270deg: (-col, row)
というわけで、先ほどの結果にちゃんと対応しています。表の示す長方形の頂点の一つは必ず座標原点に重なっていますので、座標が負のときは辺の長さを足せば正の象限に移動できます。