Calculate rotation matrix to rotate a matrix A (3d points x,y,z) to be orthogonal by 3D normal vector N I have a matrix A, which is the coordinates of a circle in 3D space. I want to rotate the circle in a way that its normal vector (orthogonal to the circle) be aligned with vector N:(x_n,y_n,z_n). I'd appreciate it if you help me with the script in Matlab.
PS: I only have matrix A [49 x 3] and vector N [1 x 3], which is the desired normal vector.
 A: I'll suppose for now that you already have the normal vector of the circle. In fact, I suspect that this normal vector is $(0,0,1)$, but I won't assume this for now. Let $a$ denote the starting normal vector, and let $b = N$ denote the target normal vector.
We could calculate a suitable rotation matrix using the procedure outlined here. Take $v = a \times b$, $s = \|v\|$, and $s = a \cdot b$. As the linked answer states, we can use the rotation matrix
$$
R = I + [v]_\times + \frac{1-c}{s^2}[v]_\times^2, \quad [v]_\times = \pmatrix{
\,\,0 & \!-v_3 & \,\,\,v_2\\
\,\,\,v_3 & 0 & \!-v_1\\
\!-v_2 & \,\,v_1 &\,\,0}.
$$
Here's a script to produce this matrix for example vectors a,b.
a = [1,2,3];
b = [-1,1,0];
v = cross(a,b);
s = norm(v)^2;
c = a*b';
c_mat = [[0,-v(3),v(2)];
          [v(3),0,-v(1)];
          [-v(2),v(1),0]];
R = eye(3) + c_mat + ((1-c)/s^2)*c_mat^2;

You can confirm that computing R*a' (or equivalently, a*R') yields a result that is parallel to b.
From there you could multiply each row by R using a for loop, but a nicer approach is to simply get the rotated points with B = A*R'.
If we want to rotate the points in A about the center of the circle, we could do the following.
center = mean(A);
B = (A - center)*R' + center;


If for some reason you need to find the starting normal vector of the circle, then one quick way to get an answer is with a = null(A - A(1,:))'.
Similarly, instead of using the cross-product to get v, you could use v = null([a;b])'.
