Please help I need to rotate a rectangle
7 次查看(过去 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!