How to rotating a stl object

60 vues (au cours des 30 derniers jours)
TOM SALIC
TOM SALIC le 18 Sep 2022
Commenté : TOM SALIC le 19 Sep 2022
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
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?
TOM SALIC
TOM SALIC le 19 Sep 2022
Modifié(e) : TOM SALIC le 19 Sep 2022
Sorry.
No I have no error but the result is the same as before. I specified the axis of rotation in the "AxelRot" function. But the stl object keeps moving off its axis of rotation.
ax=linspace(0,2*pi,10);
[p,t,tnorm]=import_stl_fast('Rotor.stl',1,2);
TR=triangulation(t,p);
filename='test.gif';
figure;
% x=[-13.30 100]; y=[0 0]; z=[89.35 89.35];
% line(x,y,z);
for idx=1:length(ax)
[PointR, R, t1] = AxelRot(p(:,:)',ax(idx)*(180/pi), [1 0 0],[-13.30 0 89.35]);
% bhold on;
h1=trisurf(t,PointR(1,:),PointR(2,:),PointR(3,:), ...
'FaceColor','black','EdgeColor','none','LineWidth',0.25);
view(90,180)
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 gif after the result.

Connectez-vous pour commenter.

Réponse acceptée

Fabio Freschi
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
  1 commentaire
TOM SALIC
TOM SALIC le 19 Sep 2022
Perfect !! it's work ! thank you @Fabio Freschi and others for the advices and solutions.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by