How to rotating a stl object
22 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2022-9-18
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?
采纳的回答
Fabio Freschi
2022-9-19
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!