How to convert 2d implicit plot to 3d plot?
5 次查看(过去 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
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)
0 个评论
更多回答(2 个)
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
2023-10-24
@Fabio
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)
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])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!