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!