|
28 | 28 | % - Toolbox rel 8-9 has XYZ angle sequence as default.
|
29 | 29 | % - 'arm', 'vehicle', 'camera' are synonyms for 'xyz', 'zyx' and 'yxz'
|
30 | 30 | % respectively.
|
| 31 | +% - these solutions are generated by symbolic/rpygen.mlx |
31 | 32 | %
|
32 | 33 | % See also rpy2tr, tr2eul.
|
33 | 34 |
|
|
87 | 88 | rpy(1) = -atan2(R(1,2), R(1,1));
|
88 | 89 | rpy(3) = -atan2(R(2,3), R(3,3));
|
89 | 90 |
|
90 |
| - rpy(2) = atan(R(1,3)*cos(rpy(1))/R(1,1)); |
| 91 | + [~,k] = max(abs( [R(1,1) R(1,2) R(2,3) R(3,3)] )); |
| 92 | + switch k |
| 93 | + case 1 |
| 94 | + rpy(2) = atan(R(1,3)*cos(rpy(1))/R(1,1)); |
| 95 | + case 2 |
| 96 | + rpy(2) = -atan(R(1,3)*sin(rpy(1))/R(1,2)); |
| 97 | + case 3 |
| 98 | + rpy(2) = -atan(R(1,3)*sin(rpy(3))/R(2,3)); |
| 99 | + case 4 |
| 100 | + rpy(2) = atan(R(1,3)*cos(rpy(3))/R(3,3)); |
| 101 | + end |
91 | 102 | end
|
92 | 103 |
|
93 | 104 | case {'zyx', 'vehicle'}
|
|
106 | 117 | else
|
107 | 118 | rpy(1) = atan2(R(3,2), R(3,3)); % R
|
108 | 119 | rpy(3) = atan2(R(2,1), R(1,1)); % Y
|
109 |
| - |
110 |
| - rpy(2) = -atan(R(3,1)*cos(rpy(1))/R(3,3)); |
| 120 | + |
| 121 | + [~,k] = max(abs( [R(1,1) R(2,1) R(3,2) R(3,3)] )); |
| 122 | + switch k |
| 123 | + case 1 |
| 124 | + rpy(2) = -atan(R(3,1)*cos(rpy(3))/R(1,1)); |
| 125 | + case 2 |
| 126 | + rpy(2) = -atan(R(3,1)*sin(rpy(3))/R(2,1)); |
| 127 | + case 3 |
| 128 | + rpy(2) = -atan(R(3,1)*sin(rpy(1))/R(3,2)); |
| 129 | + case 4 |
| 130 | + rpy(2) = -atan(R(3,1)*cos(rpy(1))/R(3,3)); |
| 131 | + end |
111 | 132 | end
|
112 | 133 |
|
113 | 134 | case {'yxz', 'camera'}
|
|
127 | 148 | rpy(1) = atan2(R(2,1), R(2,2));
|
128 | 149 | rpy(3) = atan2(R(1,3), R(3,3));
|
129 | 150 |
|
130 |
| - rpy(2) = -atan(cos(rpy(1))*R(2,3)/R(2,2)); |
| 151 | + [~,k] = max(abs( [R(2,1) R(2,2) R(1,3) R(3,3)] )); |
| 152 | + switch k |
| 153 | + case 1 |
| 154 | + rpy(2) = -atan(R(2,3)*sin(rpy(1))/R(2,1)); |
| 155 | + case 2 |
| 156 | + rpy(2) = -atan(R(2,3)*cos(rpy(1))/R(2,2)); |
| 157 | + case 3 |
| 158 | + rpy(2) = -atan(R(2,3)*sin(rpy(3))/R(1,3)); |
| 159 | + case 4 |
| 160 | + rpy(2) = -atan(R(2,3)*cos(rpy(3))/R(3,3)); |
| 161 | + end |
131 | 162 | end
|
132 | 163 |
|
133 | 164 | end
|
|
0 commit comments