3224
|
1 function qcoordinate_plot(qf,qb,qv) |
|
2 # function qcoordinate_plot(qf,qb,qv) |
|
3 # plot in the current figure a set of coordinate axes as viewed from |
|
4 # the orientation specified by quaternion qv. Inertial axes are |
|
5 # also plotted |
|
6 # qf: quaternion from reference (x,y,z) to inertial |
|
7 # qb: quaternion from reference to body |
|
8 # qv: quaternion from reference to view angle |
|
9 |
|
10 degrees = pi/180; |
|
11 d180 = 180*degrees; |
|
12 |
|
13 # construct coordinate transformation to view frame |
|
14 cm = qtransvmat(qv); |
|
15 p1 = [-1,-1,1]; p2 = [-1,-1,-1]; p3 = [1,-1,-1]; p4 = [ 1,-1, 1]; |
|
16 p5 = [-1, 1,1]; p6 = [ 1, 1, 1]; p7 = [1, 1,-1]; p8 = [-1, 1,-1]; |
|
17 # outline positive quadrant |
|
18 box1 = cm*[p4; p6; p5; p6; p7]'; |
|
19 # outline rest of the box |
|
20 box2 =cm*[p7; p8; p5; p1; p4; p3; p7; p3; p2; p1; p2; p8]'; |
|
21 |
|
22 # compute inertial to body rotation eigenaxis |
|
23 # qb = qbf*qf => qbf = qb/qf |
|
24 # |
|
25 # need to use inverse quaternion to rotate axes |
|
26 qbf = qinv(qmult(qb,qinv(qf))); |
|
27 |
|
28 [eaxv,th_eig] = quaternion(qbf); |
|
29 |
|
30 # draw 1/3 circle in x-y plane around a unit z axis |
|
31 th = (0:-12:-120)*degrees*sign(th_eig); lth = length(th); |
|
32 cpts = [0 0 0.1*cos(th) ; 0 0 0.1*sin(th); 0 1 1*ones(1,lth)]; |
|
33 |
|
34 # rotate the 1/3 circle around eigenaxis of inertial to body rotation |
|
35 # qez = qe/qz = rotation to get from z axis to eigenaxis. |
|
36 # This rotates the 1/3 circle from x-y plane to the plane normal to |
|
37 # eigenaxis |
|
38 qez = qmult(qbf,qinv(quaternion(0,0,1,0))); |
|
39 eig_xm = qtransvmat(qez); |
|
40 cpts = cm*eig_xm*cpts; |
|
41 |
|
42 # transform inertial and body quaternions to view coordinates (rotate |
|
43 # by azimuth, elevation) |
|
44 qfm = qtransvmat(qf); qbm = qtransvmat(qf); |
|
45 qf = qmult(qv,qf); qb = qmult(qv,qb); |
|
46 |
|
47 # get coordinate axes in inertial and reference frame |
|
48 jnk = qtransvmat(qf); ifv = jnk(:,1); jfv = jnk(:,2); kfv = jnk(:,3); |
|
49 jnk = qtransvmat(qb); ibv = jnk(:,1); jbv = jnk(:,2); kbv = jnk(:,3); |
|
50 |
|
51 gset size square |
|
52 axis([-2,2,-2,2]); |
|
53 [vv,theta] = quaternion(qb); |
|
54 xlabel(sprintf("rotate about eigenaxis %5.2f deg",th_eig/degrees)); |
|
55 plot( [ibv(1),0],[ibv(3),0],"-@11;x (body);", ... |
|
56 [0,jbv(1)],[0,jbv(3)],"-@21;y (body);", ... |
|
57 [0,kbv(1)],[0,kbv(3)],"-@32;z (body);", ... |
|
58 [ifv(1),0],[ifv(3),0],"-@13;x (inertial);", ... |
|
59 [0,jfv(1)],[0,jfv(3)],"-@23;y (inertial);", ... |
|
60 [0,kfv(1)],[0,kfv(3)],"-@34;z (inertial);", ... |
|
61 cpts(1,:), cpts(3,:),".-6 ;eigenaxis;", ... |
|
62 box2(1,:),box2(3,:),"-4;;", ... |
|
63 box1(1,:),box1(3,:),"-5;;"); |
|
64 endfunction |