• Remix
  • Share
  • New Entry

on 23 Oct 2021
  • 3
  • 36
  • 1
  • 0
  • 272
% Draw a water molecule
% Use spheres
[X,Y,Z]=sphere(100);
% This anon fcn draws 2 surfaces, one for the electron cloud, and one for
% the nucleus. Since this anon-fcn can only be 1 command, put the 2
% handles into an array to make it a single command.
a=@(x,y,z,s,c)[surface(s*X+x,s*Y+y,s*Z+z,'FaceC',c,'EdgeC','n','FaceA',.5);
surface(s/3*X+x,s/3*Y+y,s/3*Z+z,'FaceC',c,'EdgeC','n')];
% Draw the oxygen as blue, and hydrogen as yellow.
% In water, the hydrogen are ~104.5 degrees apart.
% I made up the distances and sizes to look cool, not be accurate.
a(0,0,0,.8,'b');
a(1,0,0,.5,'y');
a(cosd(104.5),sind(104.5),0,.5,'y');
% Pick an ok angle to view it as.
% Lock in the aspect ratio so it stays round.
% Add nice lighting, and make it bigger.
view([-220 60])
axis equal off
lighting g
camlight
camzoom(1.5)
Remix Tree