[rotate] fix rotation around second axis

This commit is contained in:
Jan Petykiewicz 2026-03-31 23:22:47 -07:00
commit 0dd2c45908
2 changed files with 32 additions and 1 deletions

View file

@ -0,0 +1,31 @@
import numpy
from numpy.testing import assert_allclose
import adze.transform
def test_rotate_x_quarter_turn() -> None:
poly = {
'vertices': numpy.array([[0.0, 1.0, 0.0]]),
'neighbors': numpy.empty((0, 3), dtype=int),
}
rotated = adze.transform.rotate(poly, numpy.pi / 2, axis=0)
assert_allclose(rotated['vertices'], [[0.0, 0.0, 1.0]], atol=1e-12)
def test_rotate_y_quarter_turn() -> None:
poly = {
'vertices': numpy.array([[0.0, 0.0, 1.0]]),
'neighbors': numpy.empty((0, 3), dtype=int),
}
rotated = adze.transform.rotate(poly, numpy.pi / 2, axis=1)
assert_allclose(rotated['vertices'], [[1.0, 0.0, 0.0]], atol=1e-12)
def test_rotate_z_quarter_turn() -> None:
poly = {
'vertices': numpy.array([[1.0, 0.0, 0.0]]),
'neighbors': numpy.empty((0, 3), dtype=int),
}
rotated = adze.transform.rotate(poly, numpy.pi / 2, axis=2)
assert_allclose(rotated['vertices'], [[0.0, 1.0, 0.0]], atol=1e-12)

View file

@ -22,7 +22,7 @@ def rotate(poly: poly_t, theta: float, axis: int) -> poly_t:
v0 = poly['vertices'][:, axis - 2].copy()
v1 = poly['vertices'][:, axis - 1]
poly['vertices'][:, axis - 2] = c * v0 - s * v1
poly['vertices'][:, axis - 1] = s * v1 + c * v0
poly['vertices'][:, axis - 1] = s * v0 + c * v1
return poly