Need to correct the following script in part of Infinitely Long Horizontal Cylinder (to be of perfect circular base)
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% 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');
0 commentaires
Réponse acceptée
Torsten
le 9 Fév 2025
%% 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);
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
