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

22 ビュー (過去 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 日 22:25
%% 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 Center および File ExchangeSurface 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