Clear Filters
Clear Filters

Plot the area of the surface

5 views (last 30 days)
Atom on 16 Aug 2023
Commented: Atom on 19 Aug 2023
Plot area of the surface that lies inside
The equation can be written in polar coordinate as $r^2=a^2 \sin(2\theta)$ which is a loop.
Please help me to plot the surface. Please highlight the portion of the surface by a color.

Accepted Answer

Ruchika on 16 Aug 2023
Edited: Ruchika on 16 Aug 2023
Hi, you can use the 'surf' function to plot the surface in MATLAB and highlight the portion that lies inside the given equation. Following is the MATLAB code that accomplishes this:
% Define the range of theta
theta = linspace(0, 2*pi, 100);
% Define the value of a
a = 1; % Replace with the desired value
% Calculate the maximum value of r based on the given equation
r_max = a * sqrt(abs(sin(2*theta)));
% Create a meshgrid for theta and r
[Theta, R] = meshgrid(theta, linspace(0, max(r_max), 100));
% Convert polar coordinates to Cartesian coordinates
X = R.*cos(Theta);
Y = R.*sin(Theta);
Z = X.*Y;
% Create a figure and plot the surface
surf(X, Y, Z, 'EdgeColor', 'none');
% Set the color for the portion inside the given equation
inside_color = [0.8, 0.2, 0.2]; % Reddish color
% Highlight the portion inside the equation by setting color
Z_highlighted = Z;
Z_highlighted((X.^2 + Y.^2).^2 > 2*a^2*X.*Y) = NaN;
% Plot the highlighted portion
hold on;
surf(X, Y, Z_highlighted, 'FaceColor', inside_color, 'EdgeColor', 'none');
% Set the view and labels
% Add a color bar to indicate the highlighted portion
colormap(gca, [inside_color; get(gca, 'color')]);
c = colorbar;
c.Label.String = 'Highlighted Portion';
% Adjust the plot settings
axis equal;
title('Surface Plot of az = xy');
Kindly replace 'a' with the desired value for the equation.
Please refer to the following documentation to know more about the 'surf' function :
Ruchika on 16 Aug 2023
Hi, the portion of the surface az = xy that lies inside the region defined by r^2 = a^2 * sin(2θ) is represented by the red surface in the plot.
In polar coordinates, the equation r^2 = a^2 * sin(2θ) represents a loop-shaped curve. The portion of the surface az = xy that lies inside this loop is highlighted in red in the plot.
Atom on 19 Aug 2023
In this plot the cylindrical shape of (X.^2 + Y.^2).^2 = 2*a^2*X.*Y is missing. Would you modify the code so that one can visualize a transparent cylindrical shape. Your code visualizes the area of the given surface inside the cylinder.

Sign in to comment.

More Answers (1)

Constantino Reyes-Aldasoro
This forum does not work like this. You have to try to do the coding first and when you run into problems, then you ask for help adding the coding that you have already done.
Atom on 16 Aug 2023
True, but I am unable to understand how to start.. In polar coordinate r^2=a^2 \sin(2\theta) will look like two loops... How to plot, I dont know really
John D'Errico
John D'Errico on 16 Aug 2023
Edited: John D'Errico on 16 Aug 2023
This is why, had I seen the question long ago, it would have been closed immediately. As now, the student thinks it is ok to post questions about homework, with no attempt made.
Not understanding how to do homework just means that a question should have been directed to the teacher. Or the students in the class could have discussed the problem amongst themselves. (That is how I survived one difficult class long ago.) And not being able to do a homework problem does not cost much.
Finally, I would point out that @Atom has posted and gotten away with 48 separate questions. Many of which seem to be like this. So I will now be forced to watch more carefully.

Sign in to comment.


Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!