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

23 ビュー (過去 30 日間)
Juan Manuel Hussein Belda
Juan Manuel Hussein Belda 2021 年 10 月 21 日
回答済み: Deepak 2023 年 6 月 21 日
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?

回答 (1 件)

Deepak
Deepak 2023 年 6 月 21 日
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.

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by