%rbwavescont.m %Create a 3D printable Plot of a continuous pattern from Red to Blue light EM waves %Steven Sahyun October 30, 2015 clear; clf(); center = 0; %The x values here are setting the depth of the print. lambda1 = 360; %blue wavelength in nm; ideally start at 400, but need to account for border. lambda2 = 740; %red wavelength in nm; ideally start at 700, but need to account for border. k1 = 2*pi/lambda1; k2 = 2*pi/lambda2; xplotwidth = 1600; 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; %make the wave patterns %need 100 values of k dlambda = (lambda2 - lambda1); lambdastepmax = 100; for lambdastep = 1:lambdastepmax lambda = lambdastep*dlambda/lambdastepmax+lambda1;%go from lambda1 to lambda2 in 100 steps of size dlambda k = 2*pi/lambda; A = y0'*sin(k*x-pi/2)*zscale+offset; z(lambdastep,:)=A(lambdastep,:); end %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; %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; WaveSurfaceRBcont = surf2solid(x*xscale, y*yscale, z*zscale, 'ELEVATION', -1); %Can change Elevation for a thicker base. stlwrite('WaveSurfaceRBcontstl.stl',WaveSurfaceRBcont)