Help plotting equations in 3D

1 回表示 (過去 30 日間)
Joseph Nettesheim
Joseph Nettesheim 2015 年 8 月 25 日
コメント済み: Joseph Nettesheim 2015 年 8 月 26 日
I am looking to plot the following in MATLAB to create a figure similar to the picture attached.
The equations are:
x=a*cos(phi);
y=a*sin(phi);
z=sqrt((c.^2./(r-(x.^2 + y.^2))).*(r-((1+epsilon).*(x.^2 + y.^2))));
where r=(a-A.*((y.^2.*(3.*x.^2-y.^2))./(x.^2+y.^2)).^B).^2;
And constants are:
a=1;
A=0.1339;
B=0.397;
c=1;
phi=0:0.001:2*pi;
epsilon=10.^-5;
NOTE: The original z equation is attached (I just solved for z and made a variable r to save space):
I have tried using plot3(X,Y,Z) using
[X,Y]=meshgrid(x,y);
z=peaks(6284);
because I found something similar in another tread.
The result is:
I appreciate any help you can offer!
  2 件のコメント
Star Strider
Star Strider 2015 年 8 月 25 日
The plot3 function requires three column vectors for its arguments. It doesn’t use meshgrid.
It will help if you post your code, or attach it if it is longer than about 20 lines. (Use the ‘paperclip’ icon and complete both steps.)
Walter Roberson
Walter Roberson 2015 年 8 月 25 日
plot3() does accept meshgrid arguments.

サインインしてコメントする。

採用された回答

Mike Garrity
Mike Garrity 2015 年 8 月 25 日
Actually, I feel like we're missing a piece of the question here.
In your code, meshgrid and peaks(6284) are creating 2D arrays. That's what you want when you're drawing a parametric surface where each point is a function of 2 parameter values. But it doesn't look like you've got a parametric surface.
From the picture, it kind of looks like you're trying to draw a parametric curve where each point is a function of a single parameter value (perhaps phi?). In that case, you're going to be generating 1D arrays for your X, Y, and Z coordinates. As Star Strider and Walter said, once you have these 1D arrays, you're probably going to pass them to the plot3 function.
But that doesn't look like what you've got either. In your code, you're generating Z as a function of X and Y, rather than as a function of the parameter value phi. But that doesn't match your picture, because in your picture there are multiple Z values for the same X & Y pair.
On the other hand, your function actually looks like an implicit surface. This is where you're drawing a surface through all of the points where the left hand side of the equation are exactly equal to 1. But, if I code that up:
cla
n = 100;
[y,x,z] = ndgrid(linspace(-.5,.5,n), ...
linspace(-.5,.5,n), ...
linspace(-1,1,n));
r = (a-A.*((y.^2.*(3.*x.^2-y.^2))./(x.^2+y.^2)).^B).^2;
f = ((x.^2+y.^2)./r).*(1+epsilon-z.^2/c.^2) + z.^2./c.^2;
isosurface(x,y,z,f,1)
view(3)
camlight
xlabel('X')
ylabel('Y')
zlabel('Z')
Then I get this:
which doesn't look at all like your picture.
Perhaps you could give us a bit more background?
BTW, you might find these examples from my blog helpful in figuring out how to draw these various types of curves and surfaces ( link1, link2, link3, link4). Perhaps one of those will give you an idea about what you're trying to draw.
  4 件のコメント
Joseph Nettesheim
Joseph Nettesheim 2015 年 8 月 25 日
Hmm I am still having a tough time with this. Even using Gustavo Morales' Ezimplot3 function ( ezimplot3) I still cannot generate the intended geometries.
Joseph Nettesheim
Joseph Nettesheim 2015 年 8 月 26 日
I have sort of figured out a solution. It doesn't look as pretty as the figure from the paper, and for some reason at z=.2 (where z^2/c^2=1) the surface is defined for all x,y. Also the shape itself doesn't quite look right.
if true
cla
a=1;
A=-3;
B=1;
c=.2;
phi=0:0.01:2*pi;
epsilon=10^-5;
n = 100;
x = linspace(-2*pi, 2*pi, n);
y = linspace(-2*pi, 2*pi, n);
z = linspace(-1, 1, n);
[X, Y, Z] = meshgrid(x, y, z);
term1num = (X.^2 + Y.^2);
term1den = (a-A.*((Y.^2.*(3.*X.^2-Y.^2))./(X.^2+Y.^2).^3).^B).^2;
term1 = term1num ./ term1den;
term2 = (1+ epsilon -(Z.^2./c.^2));
term3 = (Z.^2./c.^2);
vals = (term1 .* term2) + term3;
p = patch(isosurface(X, Y, Z, vals, 1));
isosurface(X, Y, Z, vals,1);
camlight
view(3);
xlabel('X');
ylabel('Y');
zlabel('Z');
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by