# Framed Polygon misalignment

**URL:** <https://psychtoolbox.discourse.group/t/framed-polygon-misalignment/4887>\
**Category:** Programming Help\
**Tags:** experiment-design\
**Created:** [March 10, 2023, 10:26pm UTC](https://psychtoolbox.discourse.group/t/framed-polygon-misalignment/4887 "2023-03-10T22:26:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jTneurd90](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jTneurd90](https://psychtoolbox.discourse.group/u/jTneurd90)\
**Post date:** [March 10, 2023, 10:26pm UTC](https://psychtoolbox.discourse.group/t/framed-polygon-misalignment/4887/1 "2023-03-10T22:26:37Z")

</div>

I used the example from the framed polygon tutorial  
My goals are

1. Present both left and right side triangle locations based on a matrix of x,y window dimensions ( y will be the same for both sides)
2. Create matrix containing x, y vectors for all possible sizes of the triangle based on the radius
3. Use random selection of radius (to determine size displayed) to determine size of triangles  
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);

The issue is that my triangle needs to be rotated to the right ~45 degrees. I found difficulty w/ rotation matrices due to the number of xy pairs in my matrix. How can I rotate the dimensions. If tdims can be rotated within the loop that would be optimal, otherwise outside the loop is fine. I could make either one work. Maybe I need to redesign the loop.

 ![Screenshot](https://global.discourse-cdn.com/free1/uploads/psychtoolbox/original/1X/f59ed814d8e091b34dec1f76c3540428cf8b5ba6.png)
