Skip to content
Snippets Groups Projects
Commit 9cee7c25 authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Correct two marker euler to use new convention

parent b34e618f
Branches
Tags
No related merge requests found
......@@ -38,16 +38,16 @@ class TestMarkersTransform(unittest.TestCase):
mode=cmode)
np.testing.assert_allclose(origin, [0, 0, 0],
atol=1e-07,
err_msg='origin&mode '+cmode)
err_msg='origin&mode ' + cmode)
np.testing.assert_allclose(x_axis, [1, 0, 0],
atol=1e-07,
err_msg='x-axis&mode '+cmode)
err_msg='x-axis&mode ' + cmode)
np.testing.assert_allclose(y_axis, [0, 1, 0],
atol=1e-07,
err_msg='y-axis&mode '+cmode)
err_msg='y-axis&mode ' + cmode)
np.testing.assert_allclose(z_axis, [0, 0, 1],
atol=1e-07,
err_msg='z-axis&mode '+cmode)
err_msg='z-axis&mode ' + cmode)
def test_triangle2bodyaxis_wrongmode(self):
"""Certain mode are not supported"""
......@@ -98,16 +98,15 @@ class TestMarkersTransform(unittest.TestCase):
np.testing.assert_almost_equal(perspective, [0, 0, 0, 1])
def test_twomarker2euler(self):
angles = np.pi*(np.random.rand(3) - 0.5)
angles = np.pi * (np.random.rand(3) - 0.5)
angles[0] *= 2
# angle[1] is not multipliy because in range [-pi/2,pi/2]
angles[2] *= 2
mark0 = pd.Series(data=0, index=['x', 'y', 'z'])
for axis_alignement, euler_axes, known_angle in zip(
['x-axis', 'z-axis', 'y-axis'],
['rzyx', 'ryxz', 'rzxy'],
['szyx', 'syxz', 'szxy'],
[angles[2], angles[2], angles[2]]):
triangle_mode = 'x-axis=median-from-0'
transform = compose_matrix(angles=angles,
axes=euler_axes)
......
......@@ -8,14 +8,14 @@ from scipy.optimize import minimize
_modes = []
for axel in ['x-axis', 'y-axis', 'z-axis']:
for marker in range(3):
_modes.append(axel+'=median-from-{}'.format(marker))
_modes.append(axel + '=median-from-{}'.format(marker))
for axel in ['x-axis', 'y-axis', 'z-axis']:
for marki in range(3):
for markj in range(3):
if marki == markj:
continue
_modes.append(axel+'={}-{}'.format(marki, markj))
_modes.append(axel + '={}-{}'.format(marki, markj))
def determine_mode(mode):
......@@ -34,7 +34,7 @@ def determine_mode(mode):
method = 'aligned-with'
elif len(cmode) == 3:
apexes = int(cmode[-1])
method = cmode[0]+'-'+cmode[1]
method = cmode[0] + '-' + cmode[1]
return axel, apexes, method
......@@ -44,7 +44,7 @@ def normalise_vec(vec):
if np.linalg.norm(vec) > 0:
vec = vec / np.linalg.norm(vec)
else:
vec = vec*np.nan
vec = vec * np.nan
return vec
......@@ -231,36 +231,36 @@ rotation convention.
The temporary rotation convention used two determine the euler angles are:
* rzyx, for axis alignment x-axis
* rzxy, for axis alignment y-axis
* ryxz, for axis alignment z-axis
* szyx, for axis alignment x-axis
* szxy, for axis alignment y-axis
* syxz, for axis alignment z-axis
Note: If you know the angle in your rotation convention, then you \
can run this function through a minimisation procedure with free parameter \
known angle until you get the desired orientation (see twomarkers2euler)
"""
vector = mark1-mark0
vector = mark1 - mark0
vector = normalise_vec(vector)
if axis_alignement == 'x-axis':
axes_convention = 'rzyx'
beta = np.arcsin(-vector.z)
alpha = np.arctan2(vector.y/np.cos(beta),
vector.x/np.cos(beta))
axes_convention = 'szyx'
beta = np.arcsin(vector.z)
alpha = np.arctan2(-vector.y / np.cos(beta),
vector.x / np.cos(beta))
gamma = known_angle
angles = [alpha, beta, gamma]
elif axis_alignement == 'y-axis':
axes_convention = 'rzxy'
gamma = np.arcsin(vector.z)
alpha = np.arctan2(-vector.x/np.cos(gamma),
vector.y/np.cos(gamma))
axes_convention = 'szxy'
gamma = np.arcsin(-vector.z)
alpha = np.arctan2(vector.x / np.cos(gamma),
vector.y / np.cos(gamma))
beta = known_angle
angles = [alpha, gamma, beta]
elif axis_alignement == 'z-axis':
axes_convention = 'ryxz'
gamma = np.arcsin(-vector.y)
beta = np.arctan2(vector.x/np.cos(gamma),
vector.z/np.cos(gamma))
axes_convention = 'syxz'
gamma = np.arcsin(vector.y)
beta = np.arctan2(-vector.x / np.cos(gamma),
vector.z / np.cos(gamma))
alpha = known_angle
angles = [beta, gamma, alpha]
else:
......@@ -278,7 +278,7 @@ def twomarkers2euler_score(x, mark0, mark1,
This function is used by twomarkers2euler within the minimisation of scipy
"""
angles, axes_convention = twomarkers2euler_easy_euleraxes(
mark0, mark1, axis_alignement, x)
mark0, mark1, axis_alignement, x[0])
matrix = ht.compose_matrix(
angles=angles, axes=axes_convention)
_, _, angles, _, _ = ht.decompose_matrix(matrix, axes=euler_axes)
......@@ -299,19 +299,19 @@ def twomarkers2euler(mark0, mark1, axis_alignement,
raise KeyError(
'Axis aligment {} is not supported'.format(
axis_alignement))
known_angles = np.nan*np.zeros(3)
known_angles = np.nan * np.zeros(3)
# Find the first rotation axis
index = euler_axes.find(axis_alignement[0])
if index < 1:
raise KeyError(
'Axis aligment {} can not work with euler_axes {}'.format(
axis_alignement, euler_axes))
known_angles[index-1] = known_angle
known_angles[index - 1] = known_angle
args = (mark0, mark1, axis_alignement, known_angles, euler_axes)
res = minimize(twomarkers2euler_score, x0=known_angle, args=args,
method=method, tol=tol)
angles, axes_convention = twomarkers2euler_easy_euleraxes(
mark0, mark1, axis_alignement, res.x)
mark0, mark1, axis_alignement, res.x[0])
# Build rotation matrix and decompse
matrix = ht.compose_matrix(
angles=angles, axes=axes_convention)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment