# v_skew3d

## PURPOSE

V_SKEW3D Convert between a vector and the corresponding skew-symmetric matrix

## SYNOPSIS

function y=v_skew3d(x,m)

## DESCRIPTION

    V_SKEW3D Convert between a vector and the corresponding skew-symmetric matrix

     Inputs:   x   input vector or matrix
                    size(x) must equal [3 1], [3 3], [6 1] or [4 4]
               m   m string:
                   'n'  normalize the vector to have unit magnitude
                   'z'  orthoganlize the vector so that x'Jy=0

     Outputs:  y   output matrix or vector
                    size(y) = [3 3], [3 1], [4 4] or [6 1] respectively
                    Note that v_skew3d() is its own inverse: v_skew3d(v_skew3d(x)) =  x

     3D Euclidean space
     ------------------
        If A and B are 3x1 vectors then the vector cross product is given by
        v_skew3d(A)*B = cross(A,B) = A x B. This relationship is widely used
        in computer vision.

     3D Projective space
     -------------------
     In 3D projective space, a line has 4 degrees of freedom and may be
     represented by its homogeneous 6x1 Plucker vector, A, or 4x4 Plucker
     matrix B=v_skew3d(A).
     The 6x1 Plucker vector loses one degree of freedom because it is
     homogeneous (i.e. independent of a non-zero scale factor) and another
     because it must satisfy A'*flipud(A)=0. Setting the 'n' and 'z' options
     in the second input parameter will remove these redundancies by forcing
     A'*A=1 and A'*flipud(A)=0.

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function y=v_skew3d(x,m)
    0002 %V_SKEW3D Convert between a vector and the corresponding skew-symmetric matrix
    0003 %
    0004 % Inputs:   x   input vector or matrix
    0005 %                size(x) must equal [3 1], [3 3], [6 1] or [4 4]
    0006 %           m   m string:
    0007 %               'n'  normalize the vector to have unit magnitude
    0008 %               'z'  orthoganlize the vector so that x'Jy=0
    0009 %
    0010 % Outputs:  y   output matrix or vector
    0011 %                size(y) = [3 3], [3 1], [4 4] or [6 1] respectively
    0012 %                Note that v_skew3d() is its own inverse: v_skew3d(v_skew3d(x)) =  x
    0013 %
    0014 % 3D Euclidean space
    0015 % ------------------
    0016 %    If A and B are 3x1 vectors then the vector cross product is given by
    0017 %    v_skew3d(A)*B = cross(A,B) = A x B. This relationship is widely used
    0018 %    in computer vision.
    0019 %
    0020 % 3D Projective space
    0021 % -------------------
    0022 % In 3D projective space, a line has 4 degrees of freedom and may be
    0023 % represented by its homogeneous 6x1 Plucker vector, A, or 4x4 Plucker
    0024 % matrix B=v_skew3d(A).
    0025 % The 6x1 Plucker vector loses one degree of freedom because it is
    0026 % homogeneous (i.e. independent of a non-zero scale factor) and another
    0027 % because it must satisfy A'*flipud(A)=0. Setting the 'n' and 'z' options
    0028 % in the second input parameter will remove these redundancies by forcing
    0029 % A'*A=1 and A'*flipud(A)=0.
    0030
    0031 %      Copyright (C) Mike Brookes 1998-2012
    0032 %      Version: $Id: v_skew3d.m 10865 2018-09-21 17:22:45Z dmb $
    0033 %
    0034 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0035 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0036 %
    0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0038 %   This program is free software; you can redistribute it and/or modify
    0039 %   it under the terms of the GNU Lesser General Public License as published by
    0040 %   the Free Software Foundation; either version 3 of the License, or
    0041 %   (at your option) any later version.
    0042 %
    0043 %   This program is distributed in the hope that it will be useful,
    0044 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0045 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0046 %   GNU Lesser General Public License for more details.
    0047 %
    0048 %   You can obtain a copy of the GNU Lesser General Public License from
    0049 %   https://www.gnu.org/licenses/ .
    0050 %
    0051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0052
    0053 [j,k]=size(x);
    0054 mn=nargin>1 && any(m=='n');  % normalize
    0055 mz=nargin>1 && any(m=='z');  % orthoganalize
    0056 if j==3
    0057     if k==1
    0058         if mn && x'*x>0
    0059             x=x/sqrt(x'*x);
    0060         end
    0061         y=zeros(3,3);
    0062         y([6 7 2])=x(:)';
    0063         y([8 3 4])=-x(:)';
    0064     elseif k==3
    0065         y=x([6 7 2]');
    0066         if mn && y'*y>0
    0067             y=y/sqrt(y'*y);
    0068         end
    0069     else
    0070         error('size(x) must be [3 1], [3 3], [6 1] or [4 4]');
    0071     end
    0072 elseif j==6 && k==1
    0073     x=x(:);
    0074     u=x(1:3);
    0075     v=x(6:-1:4);
    0076     if mz && u'*u>0 && v'*v>0  % orthoganalize
    0077         v = v - (u'*v)/(2*u'*u)*u;
    0078         x = [u-(v'*u)/(v'*v)*v; v([3 2 1])];
    0079     end
    0080     if mn && x'*x>0
    0081         x=x/sqrt(x'*x);
    0082     end
    0083     y=zeros(4,4);
    0084     y([5 9 13 10 8 15])=x(:)';
    0085     y([2 3 4 7 14 12])=-x(:)';
    0086 elseif j==4 && k==4
    0087     u=x([5 9 13]');
    0088     v=x([15 8 10]');
    0089     if mz && u'*u>0 && v'*v>0  % orthoganalize
    0090         v = v - (u'*v)/(2*u'*u)*u;
    0091         y = [u-(v'*u)/(v'*v)*v; v([3 2 1])];
    0092     else
    0093         y = [u; v([3 2 1])];
    0094     end
    0095     if mn && y'*y>0
    0096         y=y/sqrt(y'*y);
    0097     end
    0098 else
    0099     error('size(x) must be [3 1], [3 3], [6 1] or [4 4]');
    0100 end