How to convert 2d implicit plot to 3d plot?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ganesh Hasda
il 24 Ott 2023
Risposto: Dyuman Joshi
il 25 Ott 2023
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 Commenti
Risposta accettata
Dyuman Joshi
il 25 Ott 2023
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 Commenti
Più risposte (2)
Fabio Freschi
il 24 Ott 2023
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 Commenti
Dyuman Joshi
il 24 Ott 2023
@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
il 24 Ott 2023
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 Commenti
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!