[rotate] fix rotation around second axis
This commit is contained in:
parent
4ec8f5d414
commit
0dd2c45908
2 changed files with 32 additions and 1 deletions
31
adze/test/test_transform.py
Normal file
31
adze/test/test_transform.py
Normal 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)
|
||||||
|
|
@ -22,7 +22,7 @@ def rotate(poly: poly_t, theta: float, axis: int) -> poly_t:
|
||||||
v0 = poly['vertices'][:, axis - 2].copy()
|
v0 = poly['vertices'][:, axis - 2].copy()
|
||||||
v1 = poly['vertices'][:, axis - 1]
|
v1 = poly['vertices'][:, axis - 1]
|
||||||
poly['vertices'][:, axis - 2] = c * v0 - s * v1
|
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
|
return poly
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue