Rotation for image is off

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 Comment

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?

Sign in to comment.

Answers (0)

Products

Release

R2022b

Asked:

on 13 Mar 2023

Commented:

on 12 Apr 2023

Community Treasure Hunt

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

Start Hunting!