how to determine the trace of the graph.

4 views (last 30 days)
CHANDRABHAN Singh
CHANDRABHAN Singh on 26 Sep 2021
Answered: Nithin on 13 Oct 2023
Let's say i have plotted a cylinder in the matlab graph. Code is given below.
r = 4;
[X,Y,Z] = cylinder(r);
h = 20;
Z = Z*h;
surf(X,Y,Z);
I want to cut this cylinder with a plane (x+y+z=1) and determine the shape of the trace. I know it will be an ellipse but can we do it in matlab?

Answers (1)

Nithin
Nithin on 13 Oct 2023
Hi Chandrabhan,
I understand that you want to cut the cylinder with a plane (x+y+z=1) and determine the shape of the trace.
To implement this, kindly refer to the following code snippet-
syms x y z
% Define the equation of the plane
plane_eq = x + y + z - 1;
% Solve the equation of the plane with respect to z to get the equation of the trace
trace_eq = solve(plane_eq, z);
% Plot the original cylinder
r = 4;
[X, Y, Z] = cylinder(r);
h = 20;
Z = Z * h;
surf(X, Y, Z);
hold on;
% Plot the trace on the cylinder
fimplicit3(trace_eq, [-r, r, -r, r, 0, h]);
% Plot the graph
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Cylinder Cut with Plane');
legend('Cylinder', 'Trace');
hold off;
For more information regarding “fimplicit3” function, kindly refer to the following documentation:
I hope this answer helps you.
Regards,
Nithin Kumar.

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!