필터 지우기
필터 지우기

Plot 3D Contour plot on Surface Plot

조회 수: 12 (최근 30일)
Mark
Mark 2023년 10월 18일
댓글: Voss 2023년 10월 18일
I am trying to plot a contour 3D ontop of a surface plot. But, I do not understand why no contours are being plotted. Code being...mains cript first followed by an associated function.
%% Main Script.
%% Clear the MATLAB Workspace.
clear
clc
close all
format compact
format long
% Constants.
mu = 0.0121505856; % Mass parameter.
% Setup the mesh for computing the effective potential some range and
% in steps of n.
X = -2:0.01:2;
Y = X;
[ x, y ] = meshgrid(X, Y);
% Compute the effective potential.
U_bar = Effective_Potential(x, y, mu);
% Plot the contours of the effective potential.
figure(1),
surf(x, y, U_bar, 'EdgeColor', 'none'), ax = gca;
ax.CLim = [1.5 5.0]; grid on, hold on,
contour3(U_bar, 10, '-k', 'Linewidth', 1.5), hold off,
title('Earth-Moon Pseudo Potential', 'Fontsize', 15),
xlabel('x'), ylabel('y'), zlabel('z'),
axis([-1.5 1.5 -1.5 1.5 1.49 5.0]), view([26, 40]),
colorbar, colormap('turbo'), shading('interp')
%% Asscoiated functions.
function [ U ] = Effective_Potential(x, y, mu)
% Inputs:
% x: A 2D mesh grid of N by N size for the x-coordinate.
% y: A 2D mesh grid of N by N size for the y-coordinate.
% mu: The mass parameter for a CR3BP system.
% Outputs:
% U_bar: 2D mesh grid of N by N size containing the effective
% potential values for the given x and y coordinates.
% Compute the distance of the s/c from the smaller primary.
r_1 = sqrt((x + mu - 1).^2 + y.^2);
% Compute the distance of the s/c from the bigger primary.
r_2 = sqrt((x + mu).^2 + y.^2);
% Compute the effective potential.
U = -(-(1 - mu)./r_2 - mu./r_1 -(1/2)*(x.^2 + y.^2));
end

채택된 답변

Voss
Voss 2023년 10월 18일
Here I specify x and y as well as the contour levels in the contour3 call. Adjust as desired.
%% Main Script.
%% Clear the MATLAB Workspace.
clear
clc
close all
format compact
format long
% Constants.
mu = 0.0121505856; % Mass parameter.
% Setup the mesh for computing the effective potential some range and
% in steps of n.
X = -2:0.01:2;
Y = X;
[ x, y ] = meshgrid(X, Y);
% Compute the effective potential.
U_bar = Effective_Potential(x, y, mu);
% Plot the contours of the effective potential.
figure(1),
surf(x, y, U_bar, 'EdgeColor', 'none'), ax = gca;
ax.CLim = [1.5 5.0]; grid on, hold on,
contour3(x, y, U_bar, 1.5:0.1:5.0, '-k', 'Linewidth', 1.5), hold off,
title('Earth-Moon Pseudo Potential', 'Fontsize', 15),
xlabel('x'), ylabel('y'), zlabel('z'),
axis([-1.5 1.5 -1.5 1.5 1.49 5.0]), view([26, 40]),
colorbar, colormap('turbo'), shading('interp')
%% Asscoiated functions.
function [ U ] = Effective_Potential(x, y, mu)
% Inputs:
% x: A 2D mesh grid of N by N size for the x-coordinate.
% y: A 2D mesh grid of N by N size for the y-coordinate.
% mu: The mass parameter for a CR3BP system.
% Outputs:
% U_bar: 2D mesh grid of N by N size containing the effective
% potential values for the given x and y coordinates.
% Compute the distance of the s/c from the smaller primary.
r_1 = sqrt((x + mu - 1).^2 + y.^2);
% Compute the distance of the s/c from the bigger primary.
r_2 = sqrt((x + mu).^2 + y.^2);
% Compute the effective potential.
U = -(-(1 - mu)./r_2 - mu./r_1 -(1/2)*(x.^2 + y.^2));
end
  댓글 수: 3
Mark
Mark 2023년 10월 18일
Gotcha! Thanks so much. It works.
Voss
Voss 2023년 10월 18일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by