Using the example code from the Psychtoolbox tutorial:
anglesDeg = linspace(0, 360, numSides + 1);
anglesRad = anglesDeg * (pi / 180);
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];
for i = 1:length(screengrid(:,1:5))
screengrid(1,i) = ptb.winRect(3).* frame(i)
screengrid(2:end,i) = ptb.winRect(4).* frame(i)
anglesDeg = linspace(0, 360, numSides + 1);
anglesRad = anglesDeg * (pi / 180);
radius = [ 50 75 100 125 150 175 200 225 250];
tdims(i,1:4) = cos(anglesRad) .* radius(i) + screengrid(3);
tdims(i,5:8) = -sin(anglesRad) .* radius(i) + screengrid(6);
l= randperm(length(tdims),1);
LxPosVector = tdims(l,1:4);
LyPosVector = tdims(l,5:8);
Screen('FillPoly', ptb.win, triColor,[LxPosVector; LyPosVector]', isConvex);
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!