-
Notifications
You must be signed in to change notification settings - Fork 0
/
rigid_motion.m
66 lines (47 loc) · 1.69 KB
/
rigid_motion.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function [Y,dYdom,dYdT] = rigid_motion(X,om,T);
%rigid_motion.m
%
%[Y,dYdom,dYdT] = rigid_motion(X,om,T)
%
%Computes the rigid motion transformation Y = R*X+T, where R = rodrigues(om).
%
%INPUT: X: 3D structure in the world coordinate frame (3xN matrix for N points)
% (om,T): Rigid motion parameters between world coordinate frame and camera reference frame
% om: rotation vector (3x1 vector); T: translation vector (3x1 vector)
%
%OUTPUT: Y: 3D coordinates of the structure points in the camera reference frame (3xN matrix for N points)
% dYdom: Derivative of Y with respect to om ((3N)x3 matrix)
% dYdT: Derivative of Y with respect to T ((3N)x3 matrix)
%
%Definitions:
%Let P be a point in 3D of coordinates X in the world reference frame (stored in the matrix X)
%The coordinate vector of P in the camera reference frame is: Y = R*X + T
%where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om);
%
%Important function called within that program:
%
%rodrigues.m: Computes the rotation matrix corresponding to a rotation vector
if nargin < 3,
T = zeros(3,1);
if nargin < 2,
om = zeros(3,1);
if nargin < 1,
error('Need at least a 3D structure as input (in rigid_motion.m)');
return;
end;
end;
end;
[R,dRdom] = rodrigues(om);
[m,n] = size(X);
Y = R*X + repmat(T,[1 n]);
if nargout > 1,
dYdR = zeros(3*n,9);
dYdT = zeros(3*n,3);
dYdR(1:3:end,1:3:end) = X';
dYdR(2:3:end,2:3:end) = X';
dYdR(3:3:end,3:3:end) = X';
dYdT(1:3:end,1) = ones(n,1);
dYdT(2:3:end,2) = ones(n,1);
dYdT(3:3:end,3) = ones(n,1);
dYdom = dYdR * dRdom;
end;