Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
9cee7c25
Commit
9cee7c25
authored
6 years ago
by
Olivier Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Correct two marker euler to use new convention
parent
b34e618f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
navipy/trajectories/test_markers.py
+6
-7
6 additions, 7 deletions
navipy/trajectories/test_markers.py
navipy/trajectories/transformations.py
+24
-24
24 additions, 24 deletions
navipy/trajectories/transformations.py
with
30 additions
and
31 deletions
navipy/trajectories/test_markers.py
+
6
−
7
View file @
9cee7c25
...
...
@@ -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
'
],
[
'
r
zyx
'
,
'
r
yxz
'
,
'
r
zxy
'
],
[
'
s
zyx
'
,
'
s
yxz
'
,
'
s
zxy
'
],
[
angles
[
2
],
angles
[
2
],
angles
[
2
]]):
triangle_mode
=
'
x-axis=median-from-0
'
transform
=
compose_matrix
(
angles
=
angles
,
axes
=
euler_axes
)
...
...
This diff is collapsed.
Click to expand it.
navipy/trajectories/transformations.py
+
24
−
24
View file @
9cee7c25
...
...
@@ -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:
*
r
zyx, for axis alignment x-axis
*
r
zxy, for axis alignment y-axis
*
r
yxz, for axis alignment z-axis
*
s
zyx, for axis alignment x-axis
*
s
zxy, for axis alignment y-axis
*
s
yxz, 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
=
'
r
zyx
'
beta
=
np
.
arcsin
(
-
vector
.
z
)
alpha
=
np
.
arctan2
(
vector
.
y
/
np
.
cos
(
beta
),
vector
.
x
/
np
.
cos
(
beta
))
axes_convention
=
'
s
zyx
'
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
=
'
r
zxy
'
gamma
=
np
.
arcsin
(
vector
.
z
)
alpha
=
np
.
arctan2
(
-
vector
.
x
/
np
.
cos
(
gamma
),
vector
.
y
/
np
.
cos
(
gamma
))
axes_convention
=
'
s
zxy
'
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
=
'
r
yxz
'
gamma
=
np
.
arcsin
(
-
vector
.
y
)
beta
=
np
.
arctan2
(
vector
.
x
/
np
.
cos
(
gamma
),
vector
.
z
/
np
.
cos
(
gamma
))
axes_convention
=
'
s
yxz
'
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment