Rotating a plot about a center of origin

조회 수: 2 (최근 30일)
Ammar Babikir
Ammar Babikir 2017년 9월 1일
답변: Walter Roberson 2017년 9월 1일
Hi everybody,
I'm trying to rotate an entire plot that I have about a specific origin.
Here is my code
x = 50;
y = 50;
figure
plot( [0:100; 0:100] , [0:100; 0:100] , 'k' )
hold on
fill([0 1 1 0]+(x+1) , [0 0 1 1]+(y+3), 'blue')
fill([0 1 1 0]+(x+2) , [0 0 1 1]+(y+3), 'blue')
fill([0 1 1 0]+(x+1) , [0 0 1 1]+(50-2), 'blue')
fill([0 1 1 0]+(x+2) , [0 0 1 1]+(50-2), 'blue')
fill([0 1 1 0]+ (x+3) , [0 0 1 1]+(y), 'blue')
fill([0 1 1 0]+ (x+3) , [0 0 1 1]+ (y+1), 'blue')
fill([0 1 1 0]+(x) , [0 0 1 1]+(y), 'red')
fill([0 1 1 0]+(x+1) , [0 0 1 1]+(y), 'red')
fill([0 1 1 0]+(x) , [0 0 1 1]+(y+1), 'red')
fill([0 1 1 0]+(x+1) , [0 0 1 1]+(y+1), 'red')
fill([0 1 1 0]+(x-3) , [0 0 1 1]+(y+3), 'red')
fill([0 1 1 0]+(x-2) , [0 0 1 1]+(y+3), 'red')
fill([0 1 1 0]+(x-1) , [0 0 1 1]+(y+3), 'red')
fill([0 1 1 0]+(x-3) , [0 0 1 1]+(y-2), 'red')
fill([0 1 1 0]+(x-2) , [0 0 1 1]+(y-2), 'red')
fill([0 1 1 0]+(x-1) , [0 0 1 1]+(y-2), 'red')
fill([0 1 1 0]+(x-3) , [0 0 1 1]+(y+3), 'red')
fill([0 1 1 0]+(x-2) , [0 0 1 1]+(y+3), 'red')
fill([0 1 1 0]+(x-1) , [0 0 1 1]+(y+3), 'red')
fill([0 1 1 0]+(x-1) , [0 0 1 1]+(y), 'black')
fill([0 1 1 0]+(x-2) , [0 0 1 1]+(y), 'black')
fill([0 1 1 0]+(x-3) , [0 0 1 1]+(y), 'black')
fill([0 1 1 0]+(x+2) , [0 0 1 1]+(y), 'black')
fill([0 1 1 0]+(x-1) , [0 0 1 1]+(y+1), 'black')
fill([0 1 1 0]+(x-2) , [0 0 1 1]+(y+1), 'black')
fill([0 1 1 0]+(x-3) , [0 0 1 1]+(y+1), 'black')
fill([0 1 1 0]+(x+2) , [0 0 1 1]+(y+1), 'black')
fill([0 1 1 0]+(x+2) , [0 0 1 1]+(y+1), 'black')
fill([0 1 1 0]+(x) , [0 0 1 1]+(y-1), 'black')
fill([0 1 1 0]+(x+1) , [0 0 1 1]+(y+2), 'black')
fill([0 1 1 0]+(x+2) , [0 0 1 1]+(y+2), 'black')
fill([0 1 1 0]+(x) , [0 0 1 1]+(y+2), 'black')
fill([0 1 1 0]+(x+1) , [0 0 1 1]+(y-1), 'black')
fill([0 1 1 0]+(x+2) , [0 0 1 1]+(y-1), 'black')
fill([0 1 1 0]+(x-1) , [0 0 1 1]+(y+2), 'black')
fill([0 1 1 0]+(x-2) , [0 0 1 1]+(y+2), 'black')
fill([0 1 1 0]+(x-3) , [0 0 1 1]+(y+2), 'black')
fill([0 1 1 0]+(x-1) , [0 0 1 1]+(y-1), 'black')
fill([0 1 1 0]+(x-2) , [0 0 1 1]+(y-1), 'black')
fill([0 1 1 0]+(x-3) , [0 0 1 1]+(y-1), 'black')
hold off
hax = gca;
hax.XTick = 0:100;
hax.YTick = 0:100;
hax.XTickLabel = [];
hax.YTickLabel = [];
grid
axis square
Here is the plot that it outputs. I took a screenshot and labeled exactly where my center of origin is with its coordinates

답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 1일
If the rotation is for visual purposes, you could consider parenting to a hgtransform group and applying transforms to the group. Note that this would end up rotating the lines as well.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by