Need to correct the following script in part of Infinitely Long Horizontal Cylinder (to be of perfect circular base)

4 次查看(过去 30 天)
% MATLAB R2014b script to visualize buried gravity sources
clc; clear; close all;
% Define grid for plotting
[x, z] = meshgrid(-10:0.5:10, -10:0.5:0);
figure;
%% 1. Buried Sphere
subplot(1,3,1);
[x_s, y_s, z_s] = sphere(20);
radius = 3;
x_s = radius * x_s;
y_s = radius * y_s;
z_s = -5 + radius * z_s; % Buried at depth 5
surf(x_s, y_s, z_s, 'FaceColor', 'r', 'EdgeColor', 'none');
hold on;
fill3([-10 10 10 -10], [-10 -10 10 10], [0 0 0 0], [0.5 0.5 0.5]);
axis equal;
title('Buried Sphere');
xlabel('X'); ylabel('Y'); zlabel('Depth');
view(3);
%% 2. Infinitely Long Horizontal Cylinder
subplot(1,3,2);
[x_c, z_c] = meshgrid(-10:0.5:10, -10:0.5:0);
y_c = real(sqrt(max(0, 4 - (z_c + 5).^2))); % Cylinder at depth 5 with radius 2
surf(x_c, y_c, z_c, 'FaceColor', 'b', 'EdgeColor', 'none');
hold on;
surf(x_c, -y_c, z_c, 'FaceColor', 'b', 'EdgeColor', 'none');
fill3([-10 10 10 -10], [-10 -10 10 10], [0 0 0 0], [0.5 0.5 0.5]);
axis equal;
title('Infinitely Long Horizontal Cylinder');
xlabel('X'); ylabel('Y'); zlabel('Depth');
view(3);
%% 3. Semi-Infinite Vertical Cylinder
subplot(1,3,3);
theta = linspace(0, pi, 30);
z_v = linspace(-10, 0, 20);
[Theta, Z] = meshgrid(theta, z_v);
X = 2 * cos(Theta); % Radius = 2
Y = 2 * sin(Theta);
surf(X, Y, Z, 'FaceColor', 'g', 'EdgeColor', 'none');
hold on;
fill3([-10 10 10 -10], [-10 -10 10 10], [0 0 0 0], [0.5 0.5 0.5]);
axis equal;
title('Semi-Infinite Vertical Cylinder');
xlabel('X'); ylabel('Y'); zlabel('Depth');
view(3);
%% Final Adjustments
set(gcf, 'Color', 'w');

采纳的回答

Torsten
Torsten 2025-2-9
%% 2. Infinitely Long Horizontal Cylinder
subplot(1,3,2);
theta = linspace(0, 2*pi, 30);
x_v = linspace(-10, 0, 20);
[Theta, X] = meshgrid(theta, x_v);
Y = 2 * cos(Theta); % Radius = 2
Z = -5 + 2 * sin(Theta);
surf(X, Y, Z, 'FaceColor', 'b', 'EdgeColor', 'none');
hold on
fill3([-10 10 10 -10], [-10 -10 10 10], [0 0 0 0], [0.5 0.5 0.5]);
axis equal;
title('Infinitely Long Horizontal Cylinder');
xlabel('X'); ylabel('Y'); zlabel('Depth');
view(3);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by