How to prevent overlapping of 3D subplots when changing camera position/target?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am working on creating an animation where you have 3 different views of an orbit (each view occupying a subplot in one figure). My problem is that when I change the camera position and target (using campos/camtarget) to focus on the orbit location, the Earth and orbit in that subplot becomes incredibly large and overlaps the other subplots.
The following code is a cruder representation of my actual code, but still demonstrates the problem I am having. In the bottom left subplot, you can see that this sphere is overlapping the top left subplot after using the 'camzoom' function. In other instances, I have used 'campos' and 'camtarget' and they similarly change the camera view so that one subplot is entirely in the background. I would like to know if there is anyway where you can create a boundary box around subplots to prevent/block out overlapping or if there is some other way to prevent this plotting issue.
I also noticed that when I turn the axes back on, that changing the camera position/target/zoom also changes the background axes.
Note: in my actual code, I am not using 'sphere' but texture mapping a picture of the Earth to a 3D meshgrid surf. I don't know if that changes the problem though.
close all; clc; clear;
figure('Color', 'k'); %make background all black
set(gcf, 'Position', get(0, 'Screensize')); %make figure full screen
%Create simple orbit
t = 0:0.01:2*pi;
r = 1.3;
X = r*cos(t);
Y = r*sin(t);
Z = zeros(numel(t));
%Plotting
subplot(2,2,1)
sphere
axis equal
axis auto
set(gca, 'NextPlot','add', 'Visible','off'); %turns axes off
h1 = animatedline('Color','r','LineWidth',2);
ax1 = gca;
ax1.Clipping = 'off'; % turn sphere clipping off
subplot(2,2,2)
sphere
axis equal
set(gca, 'NextPlot','add', 'Visible','off');
h2 = animatedline('Color','r','LineWidth',2);
ax2 = gca;
ax2.Clipping = 'off'; % turn clipping off
subplot(2,2,3)
sphere
axis equal
set(gca, 'NextPlot','add', 'Visible','off');
h3 = animatedline('Color','r','LineWidth',2);
% campos([0,0,-5])
% camtarget([0,0,0])
ax3 = gca;
ax3.Clipping = 'off'; % turn clipping off
camzoom(ax3,4)
for i = 1:numel(t)
addpoints(h1,X(i),Y(i),Z(i));
addpoints(h2,X(i),Y(i),Z(i));
addpoints(h3,X(i),Y(i),Z(i));
campos(ax1,[X(i)*1.01,Y(i)*1.01,Z(i)]) %example instance of changing camera position/target
camtarget(ax1,[X(i),Y(i), Z(i)])
drawnow()
end
0 comentarios
Respuestas (1)
sai charan sampara
el 6 de Oct. de 2023
Hello GroupRing303,
As per my understanding you are trying to zoom in on one of the figures but do not want the zoomed in figure to overlap with the other figures.
Using “camzoom” disables the MATLAB’s stretch-to-fill feature (stretching of the axes to fit the window) and may result in a change to the aspect ratio of your graph. This may sometime lead to the overlapping of existing figures.
One method to prevent this is to manually set the position of the axis to prevent overlapping. This can be done by using the “Position” property of axes. In this case, setting the first figures position as follows removed the overlap:
ax1 = gca;
ax1.Clipping = 'off';
ax1.Position = [0.00,0.65,0.3347,0.3412];
Similarly other figures can also be repositioned for better visualization.
Please refer to the following reference to know more about this behaviour of “camzoom” function:
Please refer to the following reference to learn more about axis data type and its properties:
0 comentarios
Ver también
Categorías
Más información sobre Animation 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!