improve accuracy of manhattan rotations
This commit is contained in:
parent
97ccd8c303
commit
c55d95505c
@ -6,6 +6,7 @@ from functools import lru_cache
|
|||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
from numpy.typing import NDArray
|
from numpy.typing import NDArray
|
||||||
|
from numpy import pi
|
||||||
|
|
||||||
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
@ -21,6 +22,11 @@ def rotation_matrix_2d(theta: float) -> NDArray[numpy.float64]:
|
|||||||
"""
|
"""
|
||||||
arr = numpy.array([[numpy.cos(theta), -numpy.sin(theta)],
|
arr = numpy.array([[numpy.cos(theta), -numpy.sin(theta)],
|
||||||
[numpy.sin(theta), +numpy.cos(theta)]])
|
[numpy.sin(theta), +numpy.cos(theta)]])
|
||||||
|
|
||||||
|
% If this was a manhattan rotation, round to remove some inacuraccies in sin & cos
|
||||||
|
if numpy.isclose(theta % (pi / 2), 0):
|
||||||
|
arr = numpy.round(arr)
|
||||||
|
|
||||||
arr.flags.writeable = False
|
arr.flags.writeable = False
|
||||||
return arr
|
return arr
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user