I have a point cloud data in x,y,z co-ordinates. I want to generate surface with rectangular mesh of defined mesh size (i.e. length and breadth specified).

43 views (last 30 days)
I have a point cloud data in x,y,z co-ordinates. I want to generate surface with rectangular mesh element of defined mesh size (i.e. length and breadth specified). Its not necessary to use available points as vertices. I just need rectangular grid and coordinates of its vertices.
Can anyone help me with this.?
Thanks.

Answers (1)

Ameer Hamza
Ameer Hamza on 20 Apr 2020
You can use the griddata() to convert the linear vectors x, y, and z into a grid. Try this example
X = rand(100,3); % random points
x = X(:,1); % seperate them into x, y, and z variables
y = X(:,2);
z = X(:,3);
xg = linspace(min(x), max(x), 100); % coordinates of grid
yg = linspace(min(x), max(x), 100); % coordinates of grid
[Xg, Yg] = meshgrid(xg, yg); % X and Y grids
Zg = griddata(x, y, z, Xg, Yg);
surf(Xg, Yg, Zg);
griddata() can output NaN at the edge of the grid because actual data is unavailable there. If you want to interpolate to the edges(), then you can try: https://www.mathworks.com/help/matlab/ref/scatteredinterpolant.html
  4 Comments
Kaustubh Tiwarekar
Kaustubh Tiwarekar on 21 Apr 2020
For my use it doesnt matter if the point from point cloud data lies on the grid or not. I just want rectangular grid with specified dimensions fitting the surface generated by point cloud data and then I need the co-ordintes of the vertices of the grid along with a matrix ' t ' are points id contained in rectangle, nx4 array.
Ameer Hamza
Ameer Hamza on 21 Apr 2020
Following will create a 3D grid fitting the point cloud
X = rand(100,3); % random points
x = X(:,1); % seperate them into x, y, and z variables
y = X(:,2);
z = X(:,3);
xg = linspace(min(x), max(x), 100); % coordinates of grid
yg = linspace(min(y), max(y), 100);
zg = linspace(min(z), max(z), 100);
[Xg, Yg, Zg] = meshgrid(xg, yg, zg); % X and Y grids
Xg, Yg, and Zg are 3D arrays. If you want to get the coordinates of grid in a linear form, then run this
coordinate_grid = [Xg(:) Yg(:) Zg(:)];
I am not sure about the 4-th column about point id. Can you explain it further?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!