33 lines
688 B
Python
33 lines
688 B
Python
|
import math
|
||
|
|
||
|
# Size of the LUT
|
||
|
SIZE = 81
|
||
|
|
||
|
# Center of the circle
|
||
|
CX = 40
|
||
|
CY = 40
|
||
|
|
||
|
# Generate LUT
|
||
|
lut = [[0 for _ in range(SIZE)] for _ in range(SIZE)]
|
||
|
|
||
|
for i in range(SIZE):
|
||
|
for j in range(SIZE):
|
||
|
x = i - CX
|
||
|
y = j - CY
|
||
|
angle = int(math.degrees(math.atan2(y, x)) * 256 / 360)
|
||
|
if angle < 0:
|
||
|
angle += 256
|
||
|
lut[i][j] = angle
|
||
|
|
||
|
# Output C code
|
||
|
print("const int16_t atan2_lut[{}][{}] = {{".format(SIZE, SIZE))
|
||
|
for i in range(SIZE):
|
||
|
print(" {", end="")
|
||
|
for j in range(SIZE):
|
||
|
print("{:5},".format(lut[i][j]), end="")
|
||
|
if j % 10 == 9:
|
||
|
print()
|
||
|
print(" ", end="")
|
||
|
print("},")
|
||
|
print("};")
|