Point data into 3d Surface

So im learning quantum mechanics and ive just decided to plot a solution to the Schrodinger equation for a Hydrogen atom. It has a plane that oscillates in Z space and the colour through each one of those oscillations represents the probability density. Here is my code to make that a bit clearer:
%declare
e=2.718281828;
xh=4;
yh=4;
zh=6;
resolution=0.1;
t=-zh;
[x,y]=meshgrid(-xh:resolution:xh, -yh:resolution:yh);
z=((x*y)-(x*y))+t;
s=2*zh/resolution;
%Function
while 1
for k=0:s;
z=((x*y)-(x*y))+t;
c=abs(0.977.*z.*e.^(-sqrt(x.^2.+y.^2.+z.^2)/2)).^2;
surf(x,y,z,c,'edgecolor','none');
axis([-xh,xh,-yh,yh,-zh,zh]);
caxis([0.1,0.5]);
drawnow
t=t+resolution;
end
for k=0:s;
z=((x*y)-(x*y))+t;
c=abs(0.977.*z.*e.^(-sqrt(x.^2.+y.^2.+z.^2)/2)).^2;
surf(x,y,z,c,'edgecolor','none');
axis([-xh,xh,-yh,yh,-zh,zh]);
caxis([0.1,0.5]);
drawnow
t=t-resolution;
end
end
I was wondering how i could turn those colours into a 3d object i can rotate around. i know it could be achieved by saying for example every point that is red can become a vertice on the 3d mesh, i just dont know how to start putting that into code.
please ask if you would like me to clarify any more because i feel as though this description of what i want is quite vague.

回答(1 个)

Cool plot!
I suggest you experiment with scatter3. See Examples ‘> Vary Marker Color’ for what seems to be a relevant application.
Also, the exp function will calculate e for you. So you can calculate c as:
c=abs(0.977.*z.*exp(-sqrt(x.^2.+y.^2.+z.^2)/2)).^2;
It’s faster, and gives you full double precision.

7 个评论

Thanks a lot :)
Ah thankyou i didn't know that about the exp function, that will save some time !
The effect i am trying to recreate is one that can be found here:
the one in the bottom right is exactly the one my plot produces, it is the object to the right of that i am interested in creating, so i don't think the scatter is sufficient.
I watched a bit of the video. The isosurface function and its friends may be what you want. They will give a solid surface rather than a probability ‘cloud’, but they may be closer than scatter3 to what’s in the video. You can use different markers (such as points) with scatter3. You don’t have to use the default circles, so that may still be an option.
Thanks for your time, you've been real help, i'll learn around the subject and hopefully ill arrive at a solution using the suggested functions. thankyou
My pleasure!
There are people here — several of whom are MATLAB employees — who can help with isosurface if you encounter any problems.
Daniel Wray
Daniel Wray 2014-6-23
编辑:Daniel Wray 2014-6-23
Yeah after looking around on the internet i think i'm going to need some help, i cant find any information online on how to use the function for my purposes. how would i go about getting some help from someone?
I suggest experimenting with scatter3 in the interim. It’s easier to work with. All you need is a 3D matrix of points, and it seems you can readily do that with some minor changes in your code. Add subscripts to c and have it as a function of the meshgrid meshes you’ve already created. The bonus is that it would actually look like a probability space.
I managed to convert c into a 3d matrix, by that i mean it was 17x17x17, if thats what you meant? i just have no idea where to go from there. everytime i tried to make it into a scatter plot it would give an error saying that i couldn't do it unless c was a vector.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Scatter Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by