help, how i can rotate a figure in 3D using a rotation matrix.
2 views (last 30 days)
Show older comments
Ian Samuelsson
on 14 Sep 2020
Commented: Walter Roberson
on 14 Sep 2020
clearvars;
set(0,'defaultTextInterpreter','latex');
set(groot, 'defaultAxesTickLabelInterpreter','latex')
set(groot, 'defaultLegendInterpreter','latex');
set(groot,'DefaultFigureColormap',jet);
a = 2; b = 2; c = 2;
x1 = [0 a a 0 0] - a/2;
y1 = [0 0 b b 0] - b/2;
z1 = [0 0 0 0 0] - c/2;
f1 = [x1 ; y1 ; z1]
plot3(f1(1,:),f1(2,:),f1(3,:),'Color','k');
grid on; hold on;
x2 = [a a a a a] - a/2;
y2 = [0 b b 0 0] - b/2;
z2 = [0 0 c c 0] - c/2;
f2 = [x2 ; y2 ; z2]
plot3(f2(1,:),f2(2,:),f2(3,:),'Color',[0 0 0]);
x3 = [0 a a 0 0] - a/2;
y3 = [0 0 b b 0] - b/2;
z3 = [c c c c c] - c/2;
f3 = [x3 ; y3 ; z3]
plot3(f3(1,:),f3(2,:),f3(3,:),'Color',[0 0 0]);
x4 = [0 0 0 0 0] - a/2;
y4 = [0 b b 0 0] - b/2;
z4 = [0 0 c c 0] - c/2;
f4 = [x4 ; y4 ; z4]
plot3(f4(1,:),f4(2,:),f4(3,:),'Color',[0 0 0]);
maximo = max([a,b,c]);
xlim([-maximo maximo]);
ylim([-maximo maximo]);
zlim([-maximo maximo]);
scatter3(0,0,0,'k','filled');
linha = 2*[-maximo,maximo];
plot3(linha,0*linha,0*linha,'LineStyle',":",'Color',[0 0 0]);
plot3(0*linha,linha,0*linha,'LineStyle',":",'Color',[0 0 0]);
plot3(0*linha,0*linha,linha,'LineStyle',":",'Color',[0 0 0]);
xlabel('eixo $x$'); ylabel('eixo $y$'); zlabel('eixo $z$');
hold off
4 Comments
Walter Roberson
on 14 Sep 2020
You cannot rotate the entire figure. Figures are graphic windows -- everything including the standard window controls to close or minimize or maximize the window.
Back in the day... Before OpenGL existed, SGI (a once important company that created OpenGL) had its own graphics language named GL, and the window manager they used was based on DisplayPostscript . DisplayPostscript literally could rotate graphic windows -- and graphic windows for it were not restricted to being rectangular either. It was even possible to create disconnected regions...
Rectangular graphic windows might perhaps have simplified programming, but I still think computing lost something went it did not take up DisplayPostscript or similar equivalent.
Accepted Answer
Walter Roberson
on 14 Sep 2020
Edited: Walter Roberson
on 14 Sep 2020
If you need the objects to rotate but the axes to stay fixed, then you should create a hgtransform() group and set its Matrix property, likely with a transform created using makehgtform()
If you need the axes to rotate as well, then instead you should manipulate the camera properties; see https://www.mathworks.com/help/matlab/creating_plots/low-level-camera-properties.html -- or perhaps just using view() to set a matrix might work for your purposes.
0 Comments
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!