How to convert 2d implicit plot to 3d plot?

6 次查看(过去 30 天)
Following is the code for some 2 dimensional implicit curve. I want to convert it into 3d plot by rotating it about x-axis.
for c = -25:25
f = @(x,y) (x.^2 + y.^2) .* (sin(atan(y./x))).^2 .* (0.5 - (5./((sqrt(x.^2 + y.^2)).^3))) + c ;
fimplicit(f, [-10 10 -10 10])
hold on
end
hold off
How is this possible?
  3 个评论

请先登录,再进行评论。

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-10-25
Here's an attempt.
As the output from cylinder() is scaled for a unit height of the cylinder, thus it needs to be manually rescaled.
Note that this might not work for other values of c, as fzero() might not be able to find solutions.
%% The value of c for which the outer most line is produced is -25
c = -25;
f = @(x,y) (x.^2 + y.^2) .* (sin(atan(y./x))).^2 .* (0.5 - (5./((sqrt(x.^2 + y.^2)).^3))) + c ;
fimplicit(f, [-10 10])
x = linspace(-10, 10);
y = arrayfun(@(k) fzero(@(y) f(k, y), 0), x);
[X,Y,Z] = cylinder(y);
Z = rescale(Z, -10, 10);
figure
surf(Z,Y,X)

更多回答(2 个)

Fabio Freschi
Fabio Freschi 2023-10-24
For every value of c you have a different surface. So you can plot one surface at a time. For example
% param value
c = 0;
% your function
f = @(x,y) (x.^2 + y.^2) .* (sin(atan(y./x))).^2 .* (0.5 - (5./((sqrt(x.^2 + y.^2)).^3))) + c ;
% grid
x = linspace(-10,10,100);
y = linspace(-10,10,100);
[X,Y] = meshgrid(x,y);
% evaluate function
Z = f(X,Y);
% plot
figure
surf(X,Y,Z);
  2 个评论
Dyuman Joshi
Dyuman Joshi 2023-10-24
@Fabio
1 - fimplicit plots the coordinates for which the value of function is 0.
fimplicit(@(x,y) x.^2 - y.^2 - 1)
%% For comparison
x = linspace(-5, 5, 500);
y = x.';
z = x.^2 - y.^2 - 1;
%Using tolerance instead of == to compare
%as we are dealing with floating point numbers
[r,c] = find(abs(z)<1e-5);
figure
plot(x(r),y(c), '*')
axis([-5 5 -5 5])
What you have done is to evaluate the function for different values of X and Y and then plotted them via surf(), which is not the same as what fimplicit() does.
2 - OP wants to plot a solid surface that is obtained by revoling the fimplicit() output around x-axis.
c = 0;
% your function
f = @(x,y) (x.^2 + y.^2) .* (sin(atan(y./x))).^2 .* (0.5 - (5./((sqrt(x.^2 + y.^2)).^3))) + c ;
fimplicit(f, [-10 10])
xlabel('x-axis')
For the case of c = 0, the output from fimplicit() looks an ellipse, which when rotated around the x-axis would produce a torus, which is the expected output. (The surface corresponding to the lines in the middle would be hidden under the torus)
Fabio Freschi
Fabio Freschi 2023-10-24
Sorry, I have not read correctly the OP question

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2023-10-24
syms x y c
f(x,y,c) = (x.^2 + y.^2) .* (sin(atan(y./x))).^2 .* (0.5 - (5./((sqrt(x.^2 + y.^2)).^3))) + c ;
fimplicit3(f, [-10 10 -10 10 -25 25])

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by