Rotating a plot about a center of origin

3 次查看(过去 30 天)
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.

类别

Help CenterFile Exchange 中查找有关 3-D Scene Control 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by