Saturday, 10 September 2011

Matlab function to generate a homogeneous 3-D Poisson spatial distribution

This is based on Computational Statistics Toolbox by W. L. and A. R. Martinez, which has a similar algorithm in 2D. It uses John d'Errico's inhull function Inputs: N = number of data points which you want to be uniformly distributed over XP, YP, ZP which represent the vertices of the region in 3 dimensions Outputs: x,y,z are the coordinates of generated points
function [x,y,z] = csbinproc3d(xp, yp, zp, n)
x = zeros(n,1);
y = zeros(n,1);
z = zeros(n,1);
i = 1;
minx = min(xp);
maxx = max(xp);
miny = min(yp);
maxy = max(yp);
minz = min(zp);
maxz = max(zp);
cx = maxx-minx;
cy = maxy - miny;
cz = maxz - minz;
while i <= n
xt = rand(1)*cx + minx;
yt = rand(1)*cy + miny;
zt = rand(1)*cz + minz;
k = inhull([xt,yt,zt],[xp,yp,zp]);
if k == 1
% it is in the region
x(i) = xt;
y(i) = yt;
z(i) = zt;
i = i+1;
end
end
view raw csbinproc3d.m hosted with ❤ by GitHub

No comments: