Adjust Plot to Center on a specific point
35 views (last 30 days)
Show older comments
I have a 2-body plot (Earth and Mars) and the center of the plot is not on one of the bodies. I would like to shift the center to be one mars. As in making the plot mars centric.
clc
clear
close all
earthrv =[91900278.4829176; -120935705.950185; 5320.0593002369; 23.22799727906; 17.9095930906743; -0.00087982431168286];
marsrv = [-1419159.59812317; 234896748.848865; 4957065.40583768; -23.310647752292; 1.91254780464408; 0.612032897279168];
tol = 1e-12;
tof_sc= [0 203*3600*24];
hold on
plot3(earthrv(1),earthrv(2),earthrv(3), 'o', 'MarkerFaceColor', 'green', 'MarkerSize',9)
plot3(marsrv (1),marsrv (2),marsrv (3), 'o', 'MarkerFaceColor', 'red', 'MarkerSize',9)
scrv = [earthrv(1); earthrv(2); earthrv(3); earthrv(4)+ 2.75; earthrv(5)+ 2.75; -0.00087982431168286+1.15]
iter = 0;
options = odeset('RelTol', tol, 'AbsTol', tol);
[t, xd3] = ode45(@twobody, tof_sc, scrv, options);
plot3(xd3(:, 1), xd3(:, 2), xd3(:, 3), '--', 'MarkerEdgeColor', 'k');
xlabel("X");
ylabel("Y");
zlabel("Z");
view(20, 20)
grid on
hold off
%% Functions
function [dvp, dva, TOF, delta_v] = hohman(r1, r2, mu)
vt1 = sqrt(-2*mu/(r1+r2) + 2*mu/r1);%is the periapse velocity on the transfer orbit
vc1 = sqrt(mu/r1);
vt2 = sqrt(-2*mu/(r1+r2) + 2*mu/r2);%the apoapse velocity on the transfer orbit
vc2 = sqrt(mu/r2);
dvp = abs(vt1 - vc1);
dva = abs(vt2 - vc2);
delta_v = dvp + dva;
TOF = pi*sqrt((r1+r2)^3 / 8*mu);
end
function [xd] = twobody (t,x)
muu = 1.327e11;
xd = [x(4:6); (-muu/norm(x(1:3))^3)*x(1:3)];
end
0 Comments
Answers (1)
Cris LaPierre
on 8 Dec 2020
Edited: Cris LaPierre
on 8 Dec 2020
I'm not aware of a function for doing this, but what is at the center of a plot is controlled by the axes limits. With a little math, you can force mars to be in the center.
Here's one way of doing it
earthrv =[91900278.4829176; -120935705.950185; 5320.0593002369; 23.22799727906; 17.9095930906743; -0.00087982431168286];
marsrv = [-1419159.59812317; 234896748.848865; 4957065.40583768; -23.310647752292; 1.91254780464408; 0.612032897279168];
tol = 1e-12;
tof_sc= [0 203*3600*24];
hold on
plot3(earthrv(1),earthrv(2),earthrv(3), 'o', 'MarkerFaceColor', 'green', 'MarkerSize',9)
plot3(marsrv (1),marsrv (2),marsrv (3), 'o', 'MarkerFaceColor', 'red', 'MarkerSize',9)
scrv = [earthrv(1); earthrv(2); earthrv(3); earthrv(4)+ 2.75; earthrv(5)+ 2.75; -0.00087982431168286+1.15];
iter = 0;
options = odeset('RelTol', tol, 'AbsTol', tol);
[t, xd3] = ode45(@twobody, tof_sc, scrv, options);
plot3(xd3(:, 1), xd3(:, 2), xd3(:, 3), '--', 'MarkerEdgeColor', 'k');
xlabel("X");
ylabel("Y");
zlabel("Z");
view(20, 20)
grid on
hold off
%###########################################
% New code added to place mars in the center
dX = max(abs(marsrv(1)-xlim));
dY = max(abs(marsrv(2)-ylim));
dZ = max(abs(marsrv(3)-zlim));
xlim(marsrv(1)+[-dX dX]);
ylim(marsrv(2)+[-dY dY]);
zlim(marsrv(3)+[-dZ dZ]);
%###########################################
%% Functions
function [dvp, dva, TOF, delta_v] = hohman(r1, r2, mu)
vt1 = sqrt(-2*mu/(r1+r2) + 2*mu/r1);%is the periapse velocity on the transfer orbit
vc1 = sqrt(mu/r1);
vt2 = sqrt(-2*mu/(r1+r2) + 2*mu/r2);%the apoapse velocity on the transfer orbit
vc2 = sqrt(mu/r2);
dvp = abs(vt1 - vc1);
dva = abs(vt2 - vc2);
delta_v = dvp + dva;
TOF = pi*sqrt((r1+r2)^3 / 8*mu);
end
function [xd] = twobody (t,x)
muu = 1.327e11;
xd = [x(4:6); (-muu/norm(x(1:3))^3)*x(1:3)];
end
0 Comments
See Also
Categories
Find more on Data Distribution Plots 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!