Borrar filtros
Borrar filtros

How can I rotate vectors so they are in a plane defined by its normal vector?

15 visualizaciones (últimos 30 días)
I have a series of vectors that are in a given plane. However, I want to rotate them so they are in a plane that I have defined with a normal vector. How could I do it?

Respuestas (1)

Deepak
Deepak el 21 de Jun. de 2023
In MATLAB, you can use the following code to rotate a series of vectors from one plane to another plane defined by a normal vector:
Assuming:
  • given_normal is the normal vector of the given plane, with components (x, y, z)
  • desired_normal is the normal vector of the desired plane, with components (a, b, c)
  • vectors is the array of vectors (each as a column) that are to be rotated
% Step 1: Calculate the axis of rotation
axis = cross(given_normal, desired_normal);
% Step 2: Calculate the angle of rotation
angle = acos(dot(given_normal, desired_normal)/(norm(given_normal)*norm(desired_normal)));
% Step 3: Calculate the rotation matrix
c = cos(angle);
s = sin(angle);
t = 1 - c;
X = axis(1);
Y = axis(2);
Z = axis(3);
rotation_matrix = [t * X^2 + c, t * X * Y - s * Z, t * X * Z + s * Y;
t * X * Y + s * Z, t * Y^2 + c, t * Y * Z - s * X;
t * X * Z - s * Y, t * Y * Z + s * X, t * Z^2 + c];
% Step 4: Apply the rotation matrix to the vectors
rotated_vectors = rotation_matrix * vectors;
The output of this code is a new array of vectors, rotated_vectors, in which the vectors lie in the plane defined by the desired normal vector.

Categorías

Más información sobre Computational Geometry en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by