Recommended way to plot spheres

4 vues (au cours des 30 derniers jours)
Andrew
Andrew le 3 Juin 2011
Hi,
I have the x, y, and z coordinates of the oxygen and hydrogen atoms in a water molecule. For example, the coordinates of the oxygen, hydrogen1, and hydrogen2 are:
oxygen=[0.1283 1.1207 1.9259];
hydrogen1=[0.1291 1.1709 1.8394];
hydrogen2=[0.2223 1.1052 1.9564];
I can plot these with points (dots) using the plot3 command:
figure(1)
hold on
plot3(oxygen(1),oxygen(2),oxygen(3),'r.')
plot3(hydrogen1(1),hydrogen1(2),hydrogen1(3),'k.')
plot3(hydrogen2(1),hydrogen2(2),hydrogen2(3),'k.')
hold off
where the oxygen atoms is plotted in red, and the two hydrogen atoms are plotted in black. But using these dots in plot3 does not really give much of a sense of 3 dimensions. What if I would like to represent the atoms as spheres instead of dots? Is there a way to plot simple spheres by specifying the coordinates of the center point and the radius?
I see that the command sphere is one possibility. For example,
[X,Y,Z] = sphere(n)
gives me the coordinates of a sphere in three matrices that are (n+1) by (n+1) in size. However, I would still need to somehow translate the sphere to the correct center point, and then use the surf command to plot the sphere. Do you know if there is an easier way to plot spheres?
Thank you very much for your time.
Andrew DeYoung
Carnegie Mellon University

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Juin 2011
[X,Y,Z] = sphere(n);
surf(X+Xc,Y+Yc,Z+Zc)
That is, the translation is very simple.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by