Can I know how many times the cylinder rotates?

Hello.
I am a beginner in matlab.
I got the code in psychtoolbox that can make rotating cylinder.
I want to create a cylinder that rotates only once in 1.43 seconds at 60fps.
So I put number 60 in nframes and 86 in while fr (like under).
nFrames = 60; % 3 line on number 2 file
while fr <= 86 % 15 line on number 2 file
But I do not know how can I make a cylinder only once rotating in that time. I think I should put adequate number in NumFrames (8 line on number 1 file). If it is right, what number should I put it?
Because when I put 86(the same number with while fr), the resulting cylinder appears to rotate for one and a half round.
Could anyone help me, please..?
Below is rotating cylinder code file.
#number 1 file
clear;
makeCyl = 1;
%% parameters
W = 153; %width
ndot = 900;
NumFrames = 86;
stepD = 400; % ie the half perimeter of the cylinder
cylR = stepD/pi; %guarantee the cylinder aprroaches with the same distance per 180 degree as the figure walks a step
%% cylinder
if makeCyl
backCol=0.9;
dotx = sin((rand(1,ndot)-0.5)*pi)* W/2; %dots are more concentrated on the two boundaries after ttransformed to sin, more natural than sqrt
dotc = ones(1, ndot);
angs = 2*pi* rand(1,ndot);
angpf = 2*pi/NumFrames; %angle per frame
Cylin = NaN(NumFrames*3,ndot); %keep it the same format as the mov file
dotC = cell(NumFrames,1);
for zz = 1:NumFrames
Cylin(zz*3-2,:) = dotx;
Cylin(zz*3-1,:) = cylR*cos(angs);
Cylin(zz*3,:) = cylR*sin(angs); % all dots are in the same depth so that it won'd contain perspective cue when drawn by moglDrawDots3D
angs = angs-angpf;
dotc = ones(1, ndot);
dotc(:, mod(angs,2*pi)<=pi) = backCol;
dotC{zz}= [1;1;1]*dotc;
end
save('Cylin_aaa','Cylin' ,'ndot');
end
#number 2 file
InitializeMatlabOpenGL;
load('Cylin_aaa.mat')
nFrames = 60;
fr = 1;
InitializeMatlabOpenGL; % open GL reset, moglDrawDots3D Required for function execution
%Screen('Preference', 'SkipSyncTests', 1);
Screen('Preference', 'SkipSyncTests', 1) % Skip sync test for testing
whichScreen = max(Screen('Screens'));
[w, screenRect] = Screen('OpenWindow', whichScreen,[0 0 0],[]); % small screen output
ScreenCenter = [screenRect(3)/2 screenRect(4)/2];
commandwindow;
while fr <= 86
thefr = fr;
while thefr > nFrames; thefr =thefr-nFrames; end
disp(thefr); % Check frame progress
this_xyz = Cylin(thefr*3-2:thefr*3,:);
Screen('DrawDots',w, this_xyz(1:2,:),[],[255 255 255],ScreenCenter, 0);
% moglDrawDots3D(w, this_xyz, 1, [1 1 1]); %
Screen('Flip',w);
%WaitSecs(0.05); % To see the dot move slowly
fr = fr +1;
end
sca;
Thank you.

 Respuesta aceptada

Angelo Yeo
Angelo Yeo el 7 de Dic. de 2023
Editada: Angelo Yeo el 7 de Dic. de 2023
Check the script below and see that the Cylinder rotates only once during the 86 frames. I intentionally added a red marker to visually check how the cylinder rotates.
InitializeMatlabOpenGL;
load('Cylin_aaa.mat')
nFrames = 60;
fr = 1;
InitializeMatlabOpenGL; % open GL reset, moglDrawDots3D Required for function execution
Screen('Preference', 'SkipSyncTests', 1) % Skip sync test for testing
whichScreen = max(Screen('Screens'));
[w, screenRect] = Screen('OpenWindow', whichScreen,[0 0 0],[]); % small screen output
ScreenCenter = [screenRect(3)/2 screenRect(4)/2];
Screen('NominalFrameRate', w, 0, nFrames); % setting frame rate to 60 Hz
commandwindow;
while fr <= 86
Screen('DrawDots',w, Cylin(3*fr -2:3*fr-1,:),[],[255 255 255],ScreenCenter, 0);
Screen('DrawDots',w, Cylin(3*fr -2:3*fr-1,1), 10, [255,0,0] , ScreenCenter, 0); % For reference
% moglDrawDots3D(w, this_xyz, 1, [1 1 1]); %
Screen('Flip',w);
%WaitSecs(0.05); % To see the dot move slowly
fr = fr +1;
end
sca;

1 comentario

희영
희영 el 10 de Dic. de 2023
I am really sorry for the delay in accepting the answer.
I ran the code you provided, and I could check the red dot spinning! I really appreciate your help.
I hope you have a good to this week!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2022b

Preguntada:

el 6 de Dic. de 2023

Comentada:

el 10 de Dic. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by