Borrar filtros
Borrar filtros

Rotating a plot about a center of origin

3 visualizaciones (últimos 30 días)
Ammar Babikir
Ammar Babikir el 1 de Sept. de 2017
Respondida: Walter Roberson el 1 de Sept. de 2017
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

Respuestas (1)

Walter Roberson
Walter Roberson el 1 de Sept. de 2017
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.

Categorías

Más información sobre 3-D Scene Control en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by