- Determine the angle between the vector and the specified axis.
- Determine the axis of rotation that is perpendicular to both the vector and the specified axis. This axis can be found using the cross product of the two vectors.
- Construct the rotation matrix using the angle and axis of rotation. There are various methods for doing this, but one common approach is to use the Rodrigues' rotation formula.
- Apply the rotation matrix to the original vector to obtain the aligned vector.
how to align any vector with a specified axis through rotations
59 views (last 30 days)
Show older comments
Hi guys, hope you are ok. I am working with a surface and I need to rotate one vector (the cyan one) to get it aligned with the +Z axis, I know about affine transformations and can use the rotations, however I do not know how to identify the order in which I need to use these matrixes in order to do that. Its important to get the order since the same process will be applied to many other points.


2 Comments
Jenna
on 23 Feb 2023
Edited: Jan
on 23 Feb 2023
To align a vector with a specified axis through rotations, you can use a rotation matrix. Like in 9th Class Math rotation matrix will perform a series of rotations about the coordinate axes to bring the vector into alignment with the specified axis. Here are the general steps:
Here is some sample MATLAB code that demonstrates how to align a vector with the z-axis using a rotation matrix:
% Define the vector to be aligned
v = [1 2 3];
% Define the z-axis
z_axis = [0 0 1];
% Determine the angle between the vector and the z-axis
theta = acos(dot(v, z_axis)/(norm(v)*norm(z_axis)));
% Determine the axis of rotation
axis = cross(v, z_axis)/norm(cross(v, z_axis));
% Construct the rotation matrix using Rodrigues' formula
K = [0 -axis(3) axis(2); axis(3) 0 -axis(1); -axis(2) axis(1) 0];
R = eye(3) + sin(theta)*K + (1-cos(theta))*K*K;
% Apply the rotation matrix to the vector
v_aligned = R*v';
In this code, the v vector is rotated about an axis perpendicular to both v and the z_axis. The angle between v and z_axis is determined using the dot product and the cross product of v and z_axis is used to find the axis of rotation. The rotation matrix is constructed using Rodrigues' rotation formula and then applied to the v vector to obtain the aligned vector v_aligned.
Jan
on 23 Feb 2023
@Jenna: Is this a comment or an answer?
Please use the tools for formatting code. Thanks.
For the determination of the angle between two vectors see: https://www.mathworks.com/matlabcentral/answers/101590-how-can-i-determine-the-angle-between-two-vectors-in-matlab
Answers (0)
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!