Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new transformation matrix Buw #115

Merged
merged 16 commits into from
Dec 5, 2023
27 changes: 26 additions & 1 deletion bionc/bionc_numpy/transformation_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,32 @@ def _transformation_matrix_Bwu(length: float, alpha: float, beta: float, gamma:


def _transformation_matrix_Buw(length: float, alpha: float, beta: float, gamma: float) -> np.ndarray:
raise NotImplementedError("The transformation matrix Buw is not implemented yet.")
"""
Create a transformation matrix of type Buw

Parameters
----------
length: float
The length of the segment
alpha: float
The alpha angle
beta: float
The beta angle
gamma: float
The gamma angle

Returns
-------
numpy.ndarray
The transformation matrix
"""
return np.array(
[
[1, length * cos(gamma), cos(beta)],
[0, length * np.sqrt(1 - cos(gamma) ** 2 - ((cos(alpha) - cos(gamma) * cos(beta)) / sin(beta)) ** 2), 0],
[0, length * (cos(alpha) - cos(gamma) * cos(beta) / sin(beta)), sin(beta)],
]
)


def _transformation_matrix_Bvw(length: float, alpha: float, beta: float, gamma: float) -> np.ndarray:
Expand Down
27 changes: 23 additions & 4 deletions tests/test_transformation_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,19 @@ def test_transformation_matrix_Bwu():


def test_transformation_matrix_Buw():
with pytest.raises(NotImplementedError):
compute_transformation_matrix(TransformationMatrixType.Buw, length, alpha, beta, gamma)
result = compute_transformation_matrix(TransformationMatrixType.Buw, length, alpha, beta, gamma)
assert isinstance(result, np.ndarray)
assert result.shape == (3, 3)
np.testing.assert_almost_equal(
result,
np.array(
[
[1.0, 1.529684374568977, 0.8253356149096783],
[0.0, 0.9480367617186112, 0.0],
[0.0, -0.4807683268354297, 0.5646424733950354],
]
),
)


def test_transformation_matrix_Bvw():
Expand Down Expand Up @@ -135,8 +146,16 @@ def test_segment_transformation_matrix(bionc_type):
TestUtils.assert_equal(bbox.compute_transformation_matrix(matrix_type=TransformationMatrixType.Bwu), res_Bwu)
TestUtils.assert_equal(bbox.compute_transformation_matrix(matrix_type="Bwu"), res_Bwu)

with pytest.raises(NotImplementedError):
bbox.compute_transformation_matrix(matrix_type=TransformationMatrixType.Buw)
res_Buw = np.array(
[
[1.0, 1.529684374568977, 0.8253356149096783],
[0.0, 0.9480367617186112, 0.0],
[0.0, -0.4807683268354297, 0.5646424733950354],
]
)
TestUtils.assert_equal(bbox.compute_transformation_matrix(matrix_type=TransformationMatrixType.Buw), res_Buw)
TestUtils.assert_equal(bbox.compute_transformation_matrix(matrix_type="Buw"), res_Buw)

with pytest.raises(NotImplementedError):
bbox.compute_transformation_matrix(matrix_type=TransformationMatrixType.Bvw)
with pytest.raises(NotImplementedError):
Expand Down
Loading