matlabrotationlinear-algebrageometry-surfacecross-product

Rotate a vector by 90 degree via cross product


I am trying to understand a code wherein the authors have rotated vectors in 3D by 90 degrees. They used a cross-product to do so. How cross-product can incorporate rotation by 90 degrees? Any explanation would be helpful.

    % Inputs:
    %   V  #vertices by dim list of mesh vertex positions
    %   F  #faces by simplex-size list of mesh face indices
    % Gradient of a scalar function defined on piecewise linear elements (mesh)
    % is constant on each triangle i,j,k:
    % grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 / 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A
    % grad(Xijk) = Xj * (Vi - Vk)^R90 / 2A + Xk * (Vj - Vi)^R90 / 2A + 
    %             -Xi * (Vi - Vk)^R90 / 2A - Xi * (Vj - Vi)^R90 / 2A
    % where Xi is the scalar value at vertex i, Vi is the 3D position of vertex
    % i, and A is the area of triangle (i,j,k). ^R90 represent a rotation of 
    % 90 degrees
    %
    % renaming indices of vertices of triangles for convenience
    i1 = F(:,1); i2 = F(:,2); i3 = F(:,3); 
    % #F x 3 matrices of triangle edge vectors, named after opposite vertices
    v32 = V(i3,:) - V(i2,:);  v13 = V(i1,:) - V(i3,:); v21 = V(i2,:) - V(i1,:);

    % area of parallelogram is twice area of triangle
    % area of parallelogram is || v1 x v2 || 
    n  = cross(v32,v13,2); 

    % This does correct l2 norm of rows so that it contains #F list of twice
    % triangle areas
    dblA = normrow(n);

    % now normalize normals to get unit normals
    u = normalizerow(n);

    % rotate each vector 90 degrees around normal ---- ????
    eperp21 = bsxfun(@times,cross(u,v21),1./dblA);
    eperp13 = bsxfun(@times,cross(u,v13),1./dblA);

Solution

  • In 3d the cross product a x b of two vectors a and b results in a vector p := a x b that is perpendicular to both a and b.

    This means if you cross-multiply a vector with an unit vector u that represents the rotation axis, you will get a vector that is rotated 90 degrees around the rotation axis.