1

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.

ash
  • 13
  • 3

1 Answers1

0

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])'.

Ben Grossmann
  • 234,171
  • 12
  • 184
  • 355
  • Thanks for the answer. I'm not sure why it transforms my rotated points. However, the normal vector of the rotated points is parallel to the desired normal vector ( it shows it's perfectly aligned with the desired normal vector). Is there any way I can keep my points in the initial position and rotate it in its position? – ash Sep 13 '22 at 21:13
  • What exactly do you mean by "rotate it in its position"? Do you mean that you want to rotate the circle about its center? – Ben Grossmann Sep 13 '22 at 21:36
  • Yes Exactly. The current code transforms the circle to another position. – ash Sep 13 '22 at 21:36
  • @ash See my latest edit – Ben Grossmann Sep 13 '22 at 21:41
  • Great, it works! – ash Sep 13 '22 at 21:47