필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Ganesh Hasda
Ganesh Hasda 2023년 10월 24일
답변: Dyuman Joshi 2023년 10월 25일
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
Ganesh Hasda
Ganesh Hasda 2023년 10월 24일
Yes

댓글을 달려면 로그인하십시오.

채택된 답변

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