Rotation for image is off

3 次查看(过去 30 天)
Jade T
Jade T 2023-3-13
评论: Ranjeet 2023-4-12
Using the example code from the Psychtoolbox tutorial:
anglesDeg = linspace(0, 360, numSides + 1);
anglesRad = anglesDeg * (pi / 180);
radius = 200;
yPosVector = sin(anglesRad) .* radius + yCenter;
xPosVector = cos(anglesRad) .* radius + xCenter;
I've been able to make some modifications to fit my objectives, which are:
  • left and right side triangle locations based on a matrix of x,y window dimensions ( y will be the same for both sides)
  • a matrix containing x, y vectors for all possible sizes of the triangle based on the radius
  • random selection of radius (to determine size displayed)
Here is my code:
frame = [0.20 0.40 .60 .80 1];
screengrid= zeros(2,5);
for i = 1:length(screengrid(:,1:5))
screengrid(1,i) = ptb.winRect(3).* frame(i)
screengrid(2:end,i) = ptb.winRect(4).* frame(i)
end
numSides = 3;
anglesDeg = linspace(0, 360, numSides + 1);
anglesRad = anglesDeg * (pi / 180);
radius = [ 50 75 100 125 150 175 200 225 250];
nr = numel(radius);
na = numel(anglesRad)*2;
tdims = zeros(nr,na);
tdims = zeros(nr,na);
for i = 1:nr
tdims(i,1:4) = cos(anglesRad) .* radius(i) + screengrid(3); % cos = x,
tdims(i,5:8) = -sin(anglesRad) .* radius(i) + screengrid(6); % sin = y
end
l= randperm(length(tdims),1);
LxPosVector = tdims(l,1:4);
LyPosVector = tdims(l,5:8);
Screen('FillPoly', ptb.win, triColor,[LxPosVector; LyPosVector]', isConvex);
Screen('Flip', ptb.win);
I know some things can be better organized/coded however I'm still learning. The trig is actually what throws me off because I don't understand the integration of this circle in the vector dimensions for a screen (rectangle). The issue I am having is the triangle is in the wrong location. I tried a couple of vector rotation functions, but they aren't working. There are 3 x,y coordinate pairs so the dimensions are incompatible. Is there any way I can rotate/shift the location so that the base of the triangle is parallel to the bottom of the screen ( as seen in the picture)?
Thanks!
  1 个评论
Ranjeet
Ranjeet 2023-4-12
Hi Jade,
Can you specify what is ptb in your code as there is no information regarding that. Also, the picture you are referring to in the last paragraph is not present, can you provide more info?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by