8000 Added trplot() which displays a rotation (quat or matrix) as a 3D · painyeph/robotics-toolbox-python@8ca7ded · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ca7ded

Browse files
committed
Added trplot() which displays a rotation (quat or matrix) as a 3D
graphical frame. Python 3D plotting exists and is reasonably powerful, not sure it will do animations...
1 parent 570699c commit 8ca7ded

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

robotics-toolbox-python/robot/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
# Import transformations section
2323
from transform import *
2424

25+
from trplot import *
26+
2527
from jacobian import *
2628

2729
# import kinematics section
Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
function trplot(T, name, color)
2-
3-
if nargin == 1,
4-
fmt = '%c';
5-
else
6-
fmt = sprintf('%%c%s', name);
7-
end
8-
if nargin < 3,
9-
color = 'b';
10-
end
11-
12-
q = quaternion(T);
13-
plot(q, T(1:3,4), fmt, color);
1+
import matplotlib.axes3d as p3
2+
from numpy import * # for outer and arange
3+
import pylab as p # for figure
4+
from robot.Quaternion import *
5+
6+
def trplot(r, name=''):
7+
'''
8+
Plot a rotation as a set of axes aligned with the x, y and z
9+
directions of a frame rotated by C{r}.
10+
'''
11+
12+
if type(r) is matrix:
13+
q = quaternion(r);
14+
elif isinstance(r, quaternion):
15+
q = r;
16+
else:
17+
raise ValueError;
18+
19+
x = q * mat([1,0,0]);
20+
y = q * mat([0,1,0]);
21+
z = q * mat([0,0,1]);
22+
23+
fig=p.figure()
24+
ax=p3.Axes3D(fig)
25+
ax.plot3d([0,x[0,0]], [0,x[0,1]], [0,x[0,2]], color='red')
26+
ax.plot3d([0,y[0,0]], [0,y[0,1]], [0,y[0,2]], color='green')
27+
ax.plot3d([0,z[0,0]], [0,z[0,1]], [0,z[0,2]], color='blue')
28+
p.show()
29+
30+
if __name__ == "__main__":
31+
from robot.transform import *
32+
trplot( rotx(0.2) );

0 commit comments

Comments
 (0)
0