source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/torr/torr_rotations.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.9 KB
Line 
1%       By Philip Torr 2002
2%       copyright Microsoft Corp.
3%script to test 1st order approx to the rotation matrix:
4%it also checks that we are going between rotation matrices in the correct way
5
6rotation_multplier = 20;
7
8
9
10%Euler angles
11theta = 1/360 * 2 * pi * rand * rotation_multplier;
12n = 1/360 * 2 * pi * rand * rotation_multplier;
13p = 1/360 * 2 * pi * rand * rotation_multplier;
14
15R(1,1) = (1 - cos(p)) * cos(n)* ( cos(n) * cos(theta) + sin(theta) * sin(n) ) + cos(p)* cos(theta);
16R(1,2) = (1 - cos(p))* cos(n) * ( sin(n) *cos(theta) - sin(theta) *cos(n) ) - cos(p) *sin(theta);
17R(1,3) = sin(n) *sin(p);
18R(2,1) = (1 - cos(p)) *sin(n)  *( cos(n) *cos(theta) + sin(theta)* sin(n) ) + cos(p)* sin(theta);
19R(2,2) = (1 - cos(p)) *sin(n) * ( sin(n) *cos(theta) - sin(theta) *cos(n) ) + cos(p)* cos(theta);
20R(2,3) = -cos(n) * sin(p);
21R(3,1) = -sin(p) * ( sin(n) * cos(theta) - sin(theta) * cos(n));
22R(3,2) = sin(p) * ( cos(n) * cos(theta) + sin(theta) * sin(n));
23R(3,3) = cos(p);
24
25
26%angles axis
27rot_axis = [R(3,2)-R(2,3), R(1,3) - R(3,1), R(2,1) - R(1,2)];
28rot_axis = rot_axis' /norm(rot_axis);
29rot_angle = acos( (trace(R)-1)/2);
30
31disp('rotation angle in degree')
32 rot_angle * 360 /(2 * pi)
33
34%Rogregues
35II = [1 0 0; 0 1 0; 0 0 1];
36AX = torr_skew_sym(rot_axis);
37RR = cos(rot_angle) * II  + sin(rot_angle) * AX + (1 - cos(rot_angle)) * rot_axis * rot_axis';
38
39%now switch to first order (fo) approx
40
41sfo = 2 * tan ( 0.5 * rot_angle);
42lfo = sfo * rot_axis;
43
44Rfo = torr_skew_sym(lfo) + II;
45Rfo = Rfo/norm(Rfo);
46R
47Rfo
48
49disp('>> R * Rfo')
50
51R * Rfo'
52
53II - R * Rfo'
54
55
56rot_axisfo = [Rfo(3,2)-Rfo(2,3), Rfo(1,3) - Rfo(3,1), Rfo(2,1) - Rfo(1,2)];
57rot_axisfo = rot_axisfo/norm(rot_axisfo);
58rot_anglefo = acos( (trace(Rfo)-1)/2);
59
60%the axis is the same in the first order approx, but the angle is lower.
61
62rot_axisfo
63rot_anglefo * 360 /(2 * pi)
64rot_axis
65rot_angle  * 360 /(2 * pi)
Note: See TracBrowser for help on using the repository browser.