Point Cloud Generation
matlab, point-clouds
Solution
It's difficult to answer without an example but it sounds like you just want to perform a montecarlo simulation?
Lets say your shape is defined by the function `f` and that you have X, Y limits stored in two element vector e.g. xlim = [-10 10] i.e. all possible x values of this shape lie between x = -10 and x = 10 then I would suggest that you make `f` return some sort of error code if there is no value for a specific x-y pair. I'm going to assume that will be `NaN`. So `f(x,y)` is a function you are writing that either returns a `z` if it can or `NaN` if it can't
n= 10000;
counter = 1;
shape = nan(n, 3)
while counter < n
x = rand*diff(xlim) + mean(xlmin);
y = rand*diff(ylim) + mean(ylim);
z = f(x,y)
if ~isnan(z)
shape(counter, :) = [x, y, z];
counter = counter + 1
end
end
So the above code will generate 10000 (non unique, but that's easily adapted for) points randomly sample across your shape.
Now after typing this I realise that perhaps your shape is actually not all that big and maybe you can uniformly sample it rather than randomly:
for x = xlim(1):xstep:xlim(2)
for y = ylim(1):ystep:ylim(2)
shape(counter, :) = [x, y, f(x,y)];
end
end
or if you write `f` to be vectorized (preferable)
shape = [(xlim(1):xstep:xlim(2))', (ylim(1):ystep:ylim(2))', f(xlim(1):xstep:xlim(2), ylim(1):ystep:ylim(2));
and then either way
shape(isnan(shape(:, 3), :) = []; %remove the points that fell outside the shape
Problem
- I have a 3-D geometrical shape which I have to convert into a point cloud. - The resultant point cloud can be considered equivalent to a point cloud output from a Laser Scan of the object. - No mesh generation is neeeded - The points generated may be evenly spaced, or maybe just randomly spaced - doesn't matter - The 3-D shape can be provided in the form of a 3-D mathematical formula - This has to be done using MATLAB