How to generate a surface with random polyhedron "bumps"?

5 Ansichten (letzte 30 Tage)
Ayan Siddiq
Ayan Siddiq am 24 Aug. 2020
I am trying to plot a surface which has randomly generated and distrubuted polyhedron shapes. The code below shows my current code wherein there are randomized sphere sizes and locations protruding from a flat mesh grid. I am trying to achieve virtually the same thing except with user-customizable random polyhedrons instead of spheres.
I have tried experimenting with Matlab's delaunay triangulation function with no luck so far. Any help would be appreciated!
M = zeros(100,100); % initial matrix
gritDensity = 0.002; % grit per area
N = 50 % number of grit // % size(M,1).*size(M,2).*gritDensity;
sigma = 2; % stdev (width)
mu = 5; % median
[x,y] = meshgrid(1:size(M,1),1:size(M,2)); % creates grid
for k = 1:N
% random location of grit
xc = randi(size(M,1)); % picks random location on x axis between 0 and max value
yc = randi(size(M,2)); % picks random location on y axis between 0 and max value
r = normrnd(mu,sigma); % radius, rand/randn/normrand?
s = r^2-((x-xc).^2+(y-yc).^2); % equation for circle
b = s>=0; % checks if 's' is a positive number
M(b) = max(M(b),sqrt(s(b))); % indexes boolean result into the matrix M, creates "blanket" effect
end
surf(M)
axis equal
shading faceted
Output of my current code:
The type of shapes I'm looking for:
Source:

Antworten (0)

Kategorien

Mehr zu Delaunay Triangulation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by