How to rotating a stl object
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone,
I know this question has already been asked but here I am trying to spin the rotor of a wind turbine. I have the stl file and I applied the rotation matrix but the object is rotating but also in translation. My objective is simply to make it turn on the spot. Thanks for your advices.
[p,t,tnorm]=import_stl_fast('Rotor.stl',1,2);
TR=triangulation(t,p);
%trimesh(TR)
ax=linspace(0,2*pi,10);
az=pi/4;
ay=pi/4;
Ry=[cos(ay) 0 sin(ay); 0 1 0; -sin(ay) 0 cos(ay)];
Rz=[cos(az) -sin(az) 0; sin(az) cos(az) 0; 0 0 1];
filename='test.gif';
figure;
h1=trisurf(t,p(:,1),p(:,2),p(:,3), ...
'FaceColor','black','EdgeColor','none','LineWidth',0.25);
for idx=1:length(ax)
Rx=[ 1 0 0; 0 cos(idx) -sin(idx); 0 sin(idx) cos(idx)];
PointR=p*Rx;
h1=trisurf(t,PointR(:,1),PointR(:,2),PointR(:,3), ...
'FaceColor','black','EdgeColor','none','LineWidth',0.25);
%view(90,0)
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if idx == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
pause(0.1)
end
I have attached the stl file
4 commentaires
Jan
le 18 Sep 2022
If you explain, what "doesn't work" means, it is possible to help you. Do you get an error message? Does the result differ from your expectations?
Réponse acceptée
Fabio Freschi
le 19 Sep 2022
You shoud translate the points p before the rotation and then move them back
If R is your rotation matrix and the center of rotation is C = [0 Cy, Cz] (Cy and Cz identify the center of the turbine rotor)
PointR = (p-C)*R+C
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!