I am working on designing a Random Gaussian Surface that I would then be able to take to a 3D printer and print the surface to use in the project I have been working.
I thought Matlab would hopefully be the easiest method in completing this task.
About half way down the page there is two function files (rsgene1D and rsgene2D). Using these function files the creator of that site is able to produce the two images.
The image on the left being the 1D and the image on the right being the 2D. The only thing that is not included on the page is the Script file in creating these graphs.
I have been working on trying to figure out what my script file should be. But haven't been able to have any luck. Getting the 2D image on the right. Or something similar.
So this is where I ask for your help. I have placed the function file that came from the website and my script file I have created. What I am hoping is that someone can help me in determine of what it is that I am missing in my file. (Before I go to try to contact that guy who created the file and website. The website itself doesnt seem to have been updated for around 3-4 years now. So that might be a last resort).
Or if unable to help with the files I have currently.
Help me in determination of a way to created a plot that would be similar to that on the right hand side of the above image. And also be able to be changed to different types of Gaussian surfaces.
Thank you in advance!
The two are the following codes that are being used. For whatever reason the function file will not go into its own coding box. So I have also attached a photo of the file in Matlab itself.
function [f,x,y] = rsgene2D(N,rL,h,clx,cly) % % [f,x,y] = rsgene2D(N,rL,h,clx,cly) % % generates a square 2-dimensional random rough surface f(x,y) with NxN % surface points. The surface has a Gaussian height distribution and % exponential autocovariance functions (in both x and y), where rL is the % length of the surface side, h is the RMS height and clx and cly are the % correlation lengths in x and y. Omitting cly makes the surface isotropic. % % Input: N - number of surface points (along square side) % rL - length of surface (along square side) % h - rms height % clx, (cly) - correlation lengths (in x and y) % % Output: f - surface heights % x - surface points % y - surface points % % Last updated: 2010-07-26 (David Bergström). %
x = linspace(-rL/2,rL/2,N); y = linspace(-rL/2,rL/2,N); [X,Y] = meshgrid(x,y);
Z = h.*randn(N,N); % uncorrelated Gaussian random rough surface distribution % with rms height h
% isotropic surface if nargin == 4 % Gaussian filter F = exp(-(abs(X)+abs(Y))/(clx/2));
f = 2*rL/N/clx*ifft2(fft2(Z).*fft2(F));
% non-isotropic surface elseif nargin == 5 % Gaussian filter F = exp(-(abs(X)/(clx/2)+abs(Y)/(cly/2)));
f = 2*rL/N/sqrt(clx*cly)*ifft2(fft2(Z).*fft2(F));
Then the following is the script file I have been working with. This includes both the 1D and 2D information. I have mostly gotten the 1D to work. But it is not exact. But similar.
The 2D is where I have been having the most issues.
clc, clear all, close all
N = 150;
rL = 10;
h = .14;
clx = .125;
cly = .125;
[f,x,y] = rsgene2D(N,rL,h,clx,cly);
Thank you in advance for any insight into my issues.