Please help I need to rotate a rectangle
6 ビュー (過去 30 日間)
古いコメントを表示
This is what I have so far. I know how to draw a rectangle but I'm stuck on how to rotate it. Someone please help me out and show me the code I've been looking for a while. Also it needs to be done using psychtoolbox if possible. Thanks in advance.
screenPixWidth = 1280; %Screen Dimensions
screenPixHeight = 1024;
% Fixation variables
fixCrossLength = 25;
fixCrossWidth = 50;
fix1 = [screenPixWidth/2 - fixCrossWidth/2 , screenPixHeight/2 - fixCrossLength/2 , ...
screenPixWidth/2 + fixCrossWidth/2 , screenPixHeight/2 + fixCrossLength/2 ];
fix2 = [screenPixWidth/2 - fixCrossLength/2 , screenPixHeight/2 - fixCrossWidth/2, ...
screenPixWidth/2 + fixCrossLength/2 , screenPixHeight/2 + fixCrossWidth/2 ];
whichScreen = 0;
window = Screen(whichScreen, 'OpenWindow', [127 127 127]);
Screen('FillRect', window, greenCol, fix1);
0 件のコメント
回答 (3 件)
Mike Garrity
2014 年 10 月 8 日
In R2014b, you can parent a rectangle object to an hgtransform object and apply a rotation:
g = hgtransform
r = rectangle('Parent',g)
g.Matrix = makehgtform('zrotate',pi/3)
Unfortunately this didn't work correctly in earlier releases of MATLAB. If you're using an earlier version, you need to compute the rotated coordinates yourself and then use the patch command. Something like this:
x = [0 1 1 0]
y = [0 0 1 1]
patch(cos(pi/3)*x - sin(pi/3)*y, ...
sin(pi/3)*x + cos(pi/3)*y, ...
zeros(1,4), ...
'FaceColor','none')
0 件のコメント
Star Strider
2014 年 10 月 8 日
Just learning the new HG2 system in R2014b, so I kept with the previous calling syntax:
figure(1)
h = plot([0.5 2.1 2.1 0.5 0.5], [0.5 0.5 1.5 1.5 0.5]);
axis([0 4 0 2])
axis equal
for k1 = 1:24
rotate(h, [0 0 1], 0.3*k1)
refreshdata
drawnow
end
1 件のコメント
Josyula Gopala Krishna
2019 年 1 月 29 日
This doesn't rotate about the center of the given polygon, Can you please help on that? Thanks.
参考
カテゴリ
Help Center および File Exchange で Image display and manipulation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!