Home > General-Functions > SUGR > E-Matrix > sugr_bR_from_E_uv.m

sugr_bR_from_E_uv

PURPOSE ^

% b and R from E using set of pairs of directions

SYNOPSIS ^

function [b, R, code] = sugr_bR_from_E_uv(E, u, v)

DESCRIPTION ^

% b and R from E using set of pairs of directions

 [b, R, code] = sugr_bR_from_E_uv(E,u,v)

 E     = 3x3 E-matrix
 u,v   = Nx3 matrices of directions

 b     = 3x1 normalized base vector
 R     = 3x3 rotation matrix
 code  = code for signes of b and R
           0 S(b)= UZU', R = VWU
           1 S(b)= UZ'U', R = VWU
           2 S(b)= UZU', R = VW'U
           3 S(b)= UZ'U', R = VW'U
            
 Wolfgang Förstner 8/2013
 wfoerstn@uni-bonn.de

 See also sugr_E_Matrix

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% b and R from E using set of pairs of directions
0002 %
0003 % [b, R, code] = sugr_bR_from_E_uv(E,u,v)
0004 %
0005 % E     = 3x3 E-matrix
0006 % u,v   = Nx3 matrices of directions
0007 %
0008 % b     = 3x1 normalized base vector
0009 % R     = 3x3 rotation matrix
0010 % code  = code for signes of b and R
0011 %           0 S(b)= UZU', R = VWU
0012 %           1 S(b)= UZ'U', R = VWU
0013 %           2 S(b)= UZU', R = VW'U
0014 %           3 S(b)= UZ'U', R = VW'U
0015 %
0016 % Wolfgang Förstner 8/2013
0017 % wfoerstn@uni-bonn.de
0018 %
0019 % See also sugr_E_Matrix
0020 
0021 function [b, R, code] = sugr_bR_from_E_uv(E, u, v)
0022 
0023 % set basic matrices
0024 W = [0 1 0; - 1, 0, 0; 0, 0, 1];
0025 Z = [0 1 0; - 1, 0, 0; 0, 0, 0];
0026 I = size(u, 1);
0027 
0028 % svd of E
0029 [U, S, V] = svd(E);
0030 % enforce U and V to be proper rotations
0031 U = U * det(U);
0032 V = V * det(V);
0033 % check sign of b and R
0034 code = - 1;
0035 count = 0;
0036 for c = 0:3 % for all four cases set b and R
0037  
0038     count = count + 1;
0039     switch c
0040         case 0
0041             S = U * Z'*U'; R = V * W'*U';
0042         case 1
0043             S = U * Z * U';      R=V*W' * U';
0044         case 2
0045             S = U * Z'*U'; R = V * W * U';
0046         case 3
0047             S = U * Z * U';      R=V*W*U';
0048     end
0049     b = [S(3, 2); S(1, 3); S(2, 1)];
0050     b = b / norm(b);
0051     % check whether all 3D points are in direction of u and v
0052     sign_s = zeros(I, 1);
0053     sign_r = zeros(I, 1);
0054     for i = 1:I
0055         ui = u(i, :)';
0056         vi = v(i, :)';
0057         wi = R'*vi;
0058         m = cross(cross(b, ui), b);
0059         sign_s(i) = sign(det([b, m, cross(ui, wi)]));
0060         sign_r(i) = sign_s(i) * sign(m'*wi);
0061     end
0062     % check: the majority of points need to be in direction of u and v
0063     %     signs = [sign_s,sign_r];
0064     %     correct_sign = [mean(sign_s),mean(sign_r)];
0065     if mean(sign_s) > 0 && mean(sign_r) > 0
0066         code = c;
0067         return
0068     end
0069 end
0070 
0071 
0072         
0073

Generated on Mon 08-Jan-2018 17:21:49 by m2html © 2005