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

조회 수: 5 (최근 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