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.
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.You can confirm that computing
R*a'(or equivalently,a*R') yields a result that is parallel tob.From there you could multiply each row by
Rusing a for loop, but a nicer approach is to simply get the rotated points withB = A*R'.If we want to rotate the points in
Aabout the center of the circle, we could do the following.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 usev = null([a;b])'.