How to find rotational matrix for an n-dimensional subspace?

11 views (last 30 days)
Is there any matlab function that returns a rotational matrix which rotates an n-dimensional subspace along an n-dimensional vector ?
  10 Comments
Matt J
Matt J on 2 Dec 2014
When m>2, the options for the axis of rotation are non-unique. In particular, in my answer below
N=null([U,v].');
will give you a matrix for N instead of a unique vector. You must decide how you want to resolve the ambiguity. The axis of rotation must be a linear combination of the columns of N.
sam d
sam d on 3 Dec 2014
Does the N also contain the axis of rotation which will cause v to fall on its least square projection on to the subspace ?

Sign in to comment.

Answers (1)

Matt J
Matt J on 1 Dec 2014
Edited: Matt J on 1 Dec 2014
Here's a solution assuming the subspace is of dimension n-2 in R^n, see also My Commment. The solution is not unique for dimensions n>3, but the code does return one solution.
function [R,N]=getrotation(U,v)
%U - a matrix of size nx(n-2) whose columns are an orthogonal basis
% for a subspace of dimension n-2
%
%v - a given vector
%
%R - final rotation matrix
%N - axis of rotation
v=v(:)/norm(v);
N=null([U,v].'); %axis of rotation
q=U*(U.'*v);
q=q/norm(q);
A=null([N,v].');
B=null([N,q].');
AA=[N,v,A];
BB=[N,q,B].';
AA(:,3)=AA(:,3)*sign(det(BB*AA));
R=AA*BB; %final rotation
  1 Comment
Matt J
Matt J on 3 Dec 2014
Edited: Matt J on 3 Dec 2014
Does the N also contain the axis of rotation which will cause v to fall on its least square projection on to the subspace ?
In dimensions n>3, the choice of the axis of rotation and the choice of the point where v will fall are independent. In the code, I have made it so that v will map to and from its least squares projection, q. However, I could easily have made v map to any arbitrary point in the subspace spanned by U, with any axis of rotation selected from the null space spanned by N.

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!