How to convert 2d implicit plot to 3d plot?
4 ビュー (過去 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!