How to rotating a stl object

조회 수: 60 (최근 30일)
TOM SALIC
TOM SALIC 2022년 9월 18일
댓글: TOM SALIC 2022년 9월 19일
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
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?
TOM SALIC
TOM SALIC 2022년 9월 19일
편집: TOM SALIC 2022년 9월 19일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Fabio Freschi
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
  댓글 수: 1
TOM SALIC
TOM SALIC 2022년 9월 19일
Perfect !! it's work ! thank you @Fabio Freschi and others for the advices and solutions.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by