Commit 334ab403 authored by bongjinkoo's avatar bongjinkoo

Issue #7: Fix line-too-long.

parent 8263551f
Pipeline #1376 passed with stages
in 21 minutes and 49 seconds
......@@ -67,8 +67,8 @@ def validate_rotation_matrix(matrix):
3. Has 3 rows
4. Has 3 columns
5. Is orthogonal, i.e., transpose(matrix) * matrix = identity matrix.
6. Is its determinant positive (+1) (c.f., it is a reflection matrix (improper rotation)
if the determinant is negative (-1))
6. Is its determinant positive (+1) (c.f., it is a reflection matrix
(improper rotation) if the determinant is negative (-1))
:param matrix: rotation matrix
:raises: TypeError, ValueError if not
......@@ -86,16 +86,18 @@ def validate_rotation_matrix(matrix):
# Check the orthogonality: transpose(matrix) * matrix = identity matrix.
mat = np.matmul(np.transpose(matrix), matrix)
tolerance = 1e-6
id = np.eye(3)
residual = np.absolute(mat) - id
if np.flatnonzero(np.where((residual < -tolerance) | (residual > tolerance))).shape[0] > 0:
identity = np.eye(3)
residual = np.absolute(mat) - identity
if np.flatnonzero(np.where(
(residual < -tolerance) | (residual > tolerance))).shape[0] > 0:
raise ValueError("Rotation matrix should be orthogonal.")
# Check if the determinant is positive
# (assuming that the absolute value of the determinant is (close to) 1,
# which is followed by the orthogonality).
if np.linalg.det(matrix) < 0.0:
raise ValueError("Rotation matrix should have a positive determinant (+1).")
raise ValueError(
"Rotation matrix should have a positive determinant (+1).")
return True
......
......@@ -107,12 +107,14 @@ def test_rotation_matrix_invalid_because_too_few_columns():
def test_rotation_matrix_invalid_because_not_orthogonal():
with pytest.raises(ValueError):
vm.validate_rotation_matrix(np.array([[3.0, -4.0, 1.0], [5.0, 3.0, -7.0], [-9.0, 2.0, 6.0]]))
vm.validate_rotation_matrix(
np.array([[3.0, -4.0, 1.0], [5.0, 3.0, -7.0], [-9.0, 2.0, 6.0]]))
def test_rotation_matrix_invalid_because_determinant_not_positive():
with pytest.raises(ValueError):
vm.validate_rotation_matrix(np.array([[-1.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0]]))
vm.validate_rotation_matrix(
np.array([[-1.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0]]))
def test_rotation_matrix_valid():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment