Rotate a vector in higher dimension I am trying to figure out way to rotate a vector $X=[x_1,x_2,\dots\dots,x_n]$ taking another point $p$ as a reference, where the vector is in higher dimension with $n>3$ something like $n=30$.
At this point, I am not sure what are the things that I need to know if I have to rotate it. I think i need to rotate it in each of the plane, but not sure, how to do it.
Thank you for your time!
 A: I am no expert, but I tried something similar some time ago. Afaik, the problem is: there are so many ways to define what a 'rotation' in higher dimensions should be, that one usually just talks about them as the multiplication by any matrix from the special orthogonal group $SO(n)$.
If you really want to provide some specific interpretation, you have to carefully define some construction of your intended "rotation matrix" $D \in MyRotations(n)$ on your own. For example, you might combine it by a series of 2-dimensional rotations within each two-axes-plane applied in a specific order, described by $\binom{n}{2}$ many "angles" - but all that you do then is to define some "very specific linear function" (however, it might fit your needs!). Another approach might be to represent all your points according to some $n$-dimensional spherical coordinate system as the tuple $X = (r, \phi_1, \ldots, \phi_{n-1})$ of radius $r$ and angle $\phi_i$ between $X$ and some plane. Once you have defined this mapping from/to Cartesian coordinates, you can apply rotation (and scaling) easily according to this representation by adding the angles componentwise (and multiplying $r$).
At least there is some canonical way to "rotate around point $p$ as rotation center": shift $X$ by $-p$ before "rotating" by $D$, and shift the result back by $p$, i.e., compute $\hat X := D (X-p) + p$ for $D$ the "rotation matrix" of choice.
Some information on this can also be found in the "Rotation Matrix" article on Wikipedia.
A: Let's say that you have two N-dimensional vectors $X$ and $Y$ and you want to obtain matrix M, which rotates vector $X$ to the direction of vector $Y$, $$Y1=MX$$ where vector $Y1$ has the norm of $X$ but direction of $Y$ (if $X$ and $Y$ have the same norm, $Y1=Y$). You can calculate matrix M using NRMG algorithm and the following code of Matlab:
 Mx = fnAR(X); %Matrix, which rotates vector X to the direction of axis x1
 My = fnAR(Y); %Matrix, which rotates vector Y to the direction ox axis x1
 M = My'*Mx; %Matrix of rotation, which rotates X to the direction of Y

Code of Matlab function fnAR() is as follows:
function R = fnAR(X)
N = length(X);   %X have to be row vector (transposed)
R= eye(N);      %Initial rotation matrix = Identity matrix
step = 1;        %Initial step
while(step<N)    %Loop to create matrices of stages
  A= eye(N);
    n=1;
    while(n<=N-step)
        r2 = X(n)*X(n) + X(n+step)*X(n+step);
        if r2 > 0
            r = sqrt(r2);
            pcos = X(n)/r;
            psin = -X(n+step)/r;
            % Base 2-dimensional rotation 
            A(n, n) = pcos;
            A(n, n+step) = -psin;
            A(n+step, n) = psin;
            A(n+step, n+step) =  pcos;
            X(n+step)=0;
            X(n)=r;
        end
        n=n+2*step;  % Move to the next base operation
    end;
    step = step*2;
    R= A*R;  % Multiply R by current matrix of stage A
end;

