-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube-face-gridary.py
executable file
·57 lines (47 loc) · 1.41 KB
/
cube-face-gridary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
# Plain max cosine calculation for N-ary rounding on a cube,
# which also takes into account all possible scales,
# and so the resulting shape is what a good rounding function should converge towards.
# [-N .. N]
N = 4
corners = np.array(
[
[1, i / n, j / n]
for n in range(1, N + 1)
for i in range(n + 1)
for j in range(n + 1)
]
)
corners = corners / np.sqrt(np.sum(np.square(corners), axis=-1, keepdims=True))
corners = corners.T
# pixels
M = 256
middle = np.array([[1, i / (M - 1), j / (M - 1)] for i in range(M) for j in range(M)])
middle = middle / np.sqrt(np.sum(np.square(middle), axis=-1, keepdims=True))
print(corners.shape)
print(middle.shape)
cos = middle @ corners
cos = np.max(cos, axis=-1, keepdims=True)
print(cos.shape)
cos = cos.reshape((M, M))
plt.figure()
plt.imshow(cos)
plt.show()
bottom = np.concatenate([cos[..., ::-1], cos], axis=-1)
face = np.concatenate([bottom[::-1], bottom], axis=-2)
# 2*n + 1
prefix = {
1: "tern", # ternary
2: "pent", # pentary
3: "hept", # heptary
4: "enne", # enneary
5: "hendec", # hendecary
7: "pentadec", # pentadecary
15: "tricontahen", # tricontahenary
}.get(N, f"{N}_")
plt.figure(dpi=96, figsize=(face.shape[-1] / 96, face.shape[-2] / 96))
plt.figimage(face)
plt.savefig(f"images/cube-face-{prefix}ary-{2*M}x{2*M}.png")
plt.close()