Intersecting Surfaces

Here is some MATLAB code that graphs a portion of the intersection of the cylinders x2 +z2 =1 and y2 +z2 =1. The lines beginning with %% are comment statements that do no affect the code.

function surfaceintersection()
hold off
%%This creates the domain of the surface being graphed.
[x,y]=meshgrid(-1:0.05:1,-2:0.05:2);
%%This creates the first surface.
s1=surf(x,y,sqrt(1-x.^2))
%%This changes the color of the first surface.
set(s1,'facecolor','yellow')
%%This allows the second graph to be placed on top of the first graph.
hold on
s2=surf(y,x,sqrt(1-x.^2))
set(s2,'facecolor',[.1,.4,.7]) %%The color here is set using [Red,Green,Blue].
%%Plot the intersection curve of the two surfaces.
t=-1:.01:1;
x=t;
y=t;
z=sqrt(1-t.^2);
c1=plot3(x,y,z)
set(c1,'linewidth',12)
set(c1,'color',[1,.0,.1])
end

  1. Open MATLAB, type "edit" into command window, and then type the above code into the editor window. You do not have to type the comment statements. Save the file as surfaceintersection.m
  2. Run the above code by pressing F5. Edit and run until everything works okay.
  3. Edit the above code so that it shows the complete cylinders and the full curve of intersection.
  4. After you get (3) completely working, add the following after surface s1.
    set(s1,'facealpha',.4)
    set(s1,'edgecolor','none')
    Add similar statements so that all portions of the cylinders are transparent.
  5. Play with the colors as you feel inclined.
  6. Experiment with adding the code whitebg([.1,.1,.1]) or some color of your choice.
  7. Include a comment statement to indicate your name.
  8. Paste your code into an e-mail and send. I will run the code and see your beautiful picture!

Get help from

http://www2.ohlone.edu/people2/bbradshaw/matlab/programming.html

http://www2.ohlone.edu/people2/bbradshaw/matlab/plotting3dsurfaces.html

http://www2.ohlone.edu/people2/bbradshaw/matlab/plotting3dcurves.html