Plot intersection between two surfaces and a plane.

52 visualizzazioni (ultimi 30 giorni)
SCIUSCIA
SCIUSCIA il 2 Giu 2024
Commentato: Hassaan il 2 Giu 2024
I would like to plot the xy intersection of two surfaces coming from
surf command and a plane from the patch command.
I tried with the contourf, but it seems to be not possible.
Can this be done?

Risposte (1)

Hassaan
Hassaan il 2 Giu 2024
Modificato: Hassaan il 2 Giu 2024
A basic idea [other solutions may also exists]:
Define the surfaces and the plane:
  • Use the surf command to define the two surfaces.
  • Use the patch command to define the plane.
Calculate the intersections:
  • Use the contour3 command to find the intersection contours of each surface with the plane.
Plot the results:
  • Combine the surfaces, plane, and intersection curves in a single plot.
% Define the grid for the surfaces
[X, Y] = meshgrid(linspace(-5, 5, 100));
% Define the first surface
Z1 = X.^2 + Y.^2;
% Define the second surface
Z2 = 10 - (X.^2 + Y.^2);
% Define the plane (for example, z = 5)
Z_plane = 5;
% Plot the first surface
figure;
surf(X, Y, Z1);
hold on;
% Plot the second surface
surf(X, Y, Z2);
% Plot the plane
patch([-5, 5, 5, -5], [-5, -5, 5, 5], [Z_plane, Z_plane, Z_plane, Z_plane], 'g', 'FaceAlpha', 0.5);
% Calculate and plot the intersection curves
contour3(X, Y, Z1, [Z_plane, Z_plane], 'r', 'LineWidth', 2); % Intersection of first surface with the plane
contour3(X, Y, Z2, [Z_plane, Z_plane], 'b', 'LineWidth', 2); % Intersection of second surface with the plane
% Adjust the view
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Intersection of Surfaces and a Plane');
legend('Surface 1', 'Surface 2', 'Plane', 'Intersection Curve 1', 'Intersection Curve 2');
grid on;
hold off;
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  2 Commenti
Matt J
Matt J il 2 Giu 2024
@SCIUSCIA If it works perfectly, you should Accept-click it.
Hassaan
Hassaan il 2 Giu 2024
@SCIUSCIA You are welcome!
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Accedi per commentare.

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by