How can I save several axis using makehgtform?
Show older comments
Hello, I have a program that rotates a thin plate around one axis using makehgtform. After rotating the object I use getframe() to obtain the frames from the object rotating. I want to simulate for example 10 random axes and save all the frames in a variable that I will use to do other things later, how can I do that?
I want to change the values vx, vy and vz with random values between 0 and 1 to obtain 10 random axes, because right now I can only obtain one axis each time I run the code.
clc
clear all
%% THIN PLATE
vertex_matrix = [-1 0 -1; 1 0 -1; 1 0 1; -1 0 1];
faces_matrix = [1 2 3 4];
%% SIMULATE PLATE
hgtc = hgtransform('Parent',gca);
patch('Vertices',vertex_matrix,'Faces',faces_matrix,...
'FaceVertexCData',hsv(6),'FaceColor','White','FaceNormalsMode','auto','BackFaceLighting','reverselit','Parent',hgtc)
axis([-4, 4, -4, 4, -4, 4])
axis square
set(gca,'color','k') %Plot black background 'k'
az = 0;
el = 0;
view(az, el);
xlabel('x')
ylabel('y')
zlabel('z')
%% LIGHT
light('Position',[0 -5 0],'Style','local','Style','infinite'); %Place the light at infinity. The position specify the
%direction from which the light shines in parallel rays.
%% ROTATION PLATE
beta = 0.003067961576; %2*pi/2048 ---> 1 lap in 2048s
t = 0:1:2047;
for i=1:length(t)
vx=1;
vy=1;
vz=1;
RR = makehgtform('axisrotate',[vx vy vz],i*beta);
set(hgtc,'Matrix',RR);
% hp = impixelinfo;
% set(hp,'Position',[5 1 300 20]);
F(i) = getframe(gcf,[120 60 320 300]) ;
drawnow;
end
1 Comment
Raúl Alonso Merino
on 19 Nov 2018
Answers (0)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!