Clear Filters
Clear Filters

Plot intersection between two surfaces and a plane.

11 views (last 30 days)
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?

Answers (1)

Hassaan
Hassaan on 2 Jun 2024
Edited: Hassaan on 2 Jun 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 Comments
Matt J
Matt J on 2 Jun 2024
@SCIUSCIA If it works perfectly, you should Accept-click it.
Hassaan
Hassaan on 2 Jun 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.

Sign in to comment.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!