How to rotating a stl object

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 comentarios

TOM SALIC
TOM SALIC el 18 de Sept. de 2022
Thank you. I have checked the link and try to use the function but it doesn't work.
Jan
Jan el 18 de Sept. de 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 el 19 de Sept. de 2022
Editada: TOM SALIC el 19 de Sept. de 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.

Iniciar sesión para comentar.

 Respuesta aceptada

Fabio Freschi
Fabio Freschi el 19 de Sept. de 2022

0 votos

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 comentario

TOM SALIC
TOM SALIC el 19 de Sept. de 2022
Perfect !! it's work ! thank you @Fabio Freschi and others for the advices and solutions.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 18 de Sept. de 2022

Comentada:

el 19 de Sept. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by