[rotation_matrix_2d] improve manhattan angle detection
modulo causes issues with negative numbers
This commit is contained in:
parent
a38c5bb085
commit
169f66cc85
1 changed files with 3 additions and 2 deletions
|
|
@ -28,8 +28,9 @@ def rotation_matrix_2d(theta: float) -> NDArray[numpy.float64]:
|
|||
arr = numpy.array([[numpy.cos(theta), -numpy.sin(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):
|
||||
# If this was a manhattan rotation, round to remove some inaccuracies in sin & cos
|
||||
# cos(4*theta) is 1 for any multiple of pi/2.
|
||||
if numpy.isclose(numpy.cos(4 * theta), 1, atol=1e-12):
|
||||
arr = numpy.round(arr)
|
||||
|
||||
arr.flags.writeable = False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue