Recommended way to plot spheres

조회 수: 14 (최근 30일)
Andrew
Andrew 2011년 6월 3일
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

채택된 답변

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

추가 답변 (0개)

카테고리

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