%rbwaves.m %Create a 3D printable Plot of Red and Blue light EM waves %segments %Steven Sahyun October 30, 2015 clear; clf(); center = 0; %The x values here are setting the depth of the print. lambda1 = 400; %blue wavelength in nm lambda2 = 700; %red wavelength in nm k1 = 2*pi/lambda1; k2 = 2*pi/lambda2; xplotwidth = 4*lambda1; xmin = center; xmax = center+xplotwidth; xstep = (xmax-xmin)/100; %100 data points x = xmin:xstep:xmax; x0 = 0*x+1; %Change these y values to affect the shape of the graph. You can change the %begining and end points for "plotting" by changing ymin and ymax. yplotwidth = 10; ymin = center-yplotwidth; %Change the start point in terms of # of standard deviations ymax = center+yplotwidth; %Change the end point in terms of # of standard deviations ystep = (ymax-ymin)/100; %100 data points y = ymin:ystep:ymax; y0 = 0*y+1; meshgrid(x,y); zscale = 0.5; offset = 0.55; z = y0'*x0; z1 = y0'*sin(k1*x-pi/2)*zscale+offset; z2 = y0'*sin(k2*x-pi/2)*zscale+offset; z(1:50, :) = z1(1:50, :); z(51:100, :) = z2(51:100, :); %Provide a border with height of 0 that is 10 rows wide. %get size of z, m = rows, n=columns [m, n] = size(z); z(1:10, :) = 0; z(n-10:n, :) = 0; % separate the two wave patterns z(45:55, :) = 0; %Plot the surface surf(x,y,z); axis([xmin, xmax, ymin, ymax, 0, zscale+offset]) %Convert to a 3D printable file; You need to have stlwrite.m and surf2solid.m by %Sven Holcombe in the same directory as this file. %See: http://jmumakerlab.blogspot.com/2013/11/exporting-stl-from-matlab.html % http://www.mathworks.com/matlabcentral/fileexchange/42876-surf2solid-make-a-solid-volume-from-a-surface-for-3d-printing % http://www.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-filename--varargin- %minz = 0; %maxz = zscale; %c=255*((z+minz)/maxz); %For getting the 3D print to work out xscale = 0.05; yscale = 3; zscale = 10; WaveSurfaceRB = surf2solid(x*xscale, y*yscale, z*zscale, 'ELEVATION', -1); %Can change Elevation for a thicker base. stlwrite('WaveSurfaceRBstl.stl',WaveSurfaceRB)