回答編集履歴

2

追記

2018/11/16 14:40

投稿

katoy
katoy

スコア22324

test CHANGED
@@ -139,3 +139,103 @@
139
139
  追記
140
140
 
141
141
  展開図の様子を 2次元配列(Matrix) で表現し、回転操作を Matrix の乗算で表現することも可能と思います。
142
+
143
+
144
+
145
+ 追記2
146
+
147
+ numpy を使って行列の演算で書いて見ました。(乗算だけでできると思っていたが、足し算やその他の演算も使いました)
148
+
149
+ m.py
150
+
151
+ ```python3
152
+
153
+ import numpy as np
154
+
155
+
156
+
157
+ def up(dice, repeat=1):
158
+
159
+ front_ary = np.array([
160
+
161
+ [0, 0, 0, 0],
162
+
163
+ [0, 1, 0, 0],
164
+
165
+ [0, 0, 0, 0],
166
+
167
+ [0, 0, 0, 0]
168
+
169
+ ])
170
+
171
+
172
+
173
+ for i in range(0, repeat % 4):
174
+
175
+ d1 = np.matmul(dice, front_ary)[[1, 2, 3, 0]]
176
+
177
+ d2 = np.matmul(front_ary, dice)
178
+
179
+ d2[1,1] = 0
180
+
181
+ dice = d1 + d2
182
+
183
+ dice[1,3] = dice[3, 1]
184
+
185
+ return dice
186
+
187
+
188
+
189
+ def down(dice, count = 1):
190
+
191
+ return up(dice, -count)
192
+
193
+
194
+
195
+ def left(dice, repeat=1):
196
+
197
+ return up(dice.transpose(), repeat).transpose()
198
+
199
+
200
+
201
+ def right(dice, count = 1):
202
+
203
+ return left(dice, -count)
204
+
205
+
206
+
207
+ dice = np.array([
208
+
209
+ [0, 3, 0, 0],
210
+
211
+ [2, 1, 5, 6],
212
+
213
+ [0, 4, 0, 0],
214
+
215
+ [0, 6, 0, 0]
216
+
217
+ ])
218
+
219
+ print(dice)
220
+
221
+ print(up(dice))
222
+
223
+ print(down(up(dice)))
224
+
225
+ print()
226
+
227
+
228
+
229
+ print(dice)
230
+
231
+ print(left(dice))
232
+
233
+ print(right(left(dice)))
234
+
235
+ ```
236
+
237
+
238
+
239
+ 実行例
240
+
241
+ ![イメージ説明](fd5e143254f0744232e0825a62ed5253.png)

1

追記

2018/11/16 14:40

投稿

katoy
katoy

スコア22324

test CHANGED
@@ -133,3 +133,9 @@
133
133
 
134
134
 
135
135
  サイコロの展開図を表示するようにしてます。
136
+
137
+
138
+
139
+ 追記
140
+
141
+ 展開図の様子を 2次元配列(Matrix) で表現し、回転操作を Matrix の乗算で表現することも可能と思います。