Rotate 3D Shape so Specific Face is Normal to Given Vector
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a 3D shape made up of faces and vertices. I've been struggling to create code that will respond dynamically to rotate the shape so that the red face is 1. Normal to a given input vector; 2. The red face points in the direction of the vector.

For example, if the above photo is the starting state and I am given an input vector of [-1, 0, 0], I expect an output like this where the red face is: 1. Orthogonal to the vector; 2. The red face is closer to -x than the blue body.

My issue is that I can't figure out how to rotate the red square so that it is normal to the vector while also rotating the blue body to properly maintain the original shape. Enclosed is a copy of the shape, if you'd like to use that as a starting point. Any input is greatly appreciated!
2 comentarios
Respuesta aceptada
Matt J
el 6 de Dic. de 2023
Editada: Matt J
el 6 de Dic. de 2023
function [alpha,direction]=vecrot(vstart,vend)
%Find rotation parameters that rotate one vector into coincidence with another about their
%common perpendicular axis.
%
% [alpha,direction]=vecrot(vstart,vend)
%
%IN:
%
% vstart: Initial normal vector
% vend: Final normal vector
%
%OUT:
%
% alpha: the rotation angle in degrees
% direction: the rotation axis
vstart=vstart(:)/norm(vstart);
vend=vend(:)/norm(vend);
direction=cross(vstart,vend);
b=vend.'*vstart;
alpha = atan2d(sqrt(1-b^2),b);
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Interactions, Camera Views, and Lighting 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!