extract planes from point cloud

I have a point cloud and I want to extract series of planes through which the data passes. for each such plane, one can identify the points from scan data which belong to the plane.
how i do that?

4 Comments

Please attach some, your attempts. Maybe an image with explanations
downsampled points.png
this is how my point cloud looks like. 3x3 matrix with x,y,z coordinates.
I want series of planes that represents points in circle(curve). I expect to have many planes and layers of points in circle.
I tried using pcfitplane but it only shows 1 plane and the result is not good.
first plane.png
You want to set some plane and indificate which points belong to it? Is it correct?
yes. that's exactly what I want. do you have any idea how?

Sign in to comment.

 Accepted Answer

darova
darova on 3 Oct 2019
Here is my attempt
Here is what it produces:
See the attached script

33 Comments

thank you! I just want to ask how did you define the plane?
p0 = [0 0 0];
p1 = [2 2 2];
p2 = [0 3 3]
is this coordinate x,y,z or what?
9.png
i tried this code and i think it's going to work. i just have to make the plane horizontally set up.
thank you so much.
I just want to ask how did you define the plane?
Exactly!
Don't forget about distance. It determines which points belong to plane
mindist = 0.2; % minumum distance to plane
a.png
As you can see, I set up the plane so that i can get points in circle on a plane.
because i want something like this (example) at the end,
boundary curves jadi.jpg
but when i plot the points on plane only it became like this
b.png
and only can form a circle when i rotate it and view from z-axis
c.PNG
p0 = [0 0 0];
p1 = [2 2 0];
p2 = [0 3 0];
plane that i made and mindist that i used is
mindist = 0.4;
why it became like this? do you have any idea? thanks in advance
I think it is a scale. Try
zlim([ min(z) max(z) ])
yeah it works well thanks you are my saviour!
also my next step is to connect the points to be a curve. but when i use plot3 command it became like this
r.png
it means the points are not arranged in sequence. to arrange the points in sequence, i read that i have to use nearest neighbour / travelling salesman problem.
but i really don't have any idea on that.
Just sort them
[t,r] = cart2pol(x,y);
[~,ix] = sort(t); % sort angle
plot3(x(ix),y(ix),z(ix))
oh my god it works! thanks!
I cannot resist to ask one last question because you are so good in this,
is it possible to set fixed number of points on a plane?
for example i want 90 points only on each plane?
[t,r] = cart2pol(x,y);
[~,ix] = sort(t); % sort angle
n = length(ix);
ii = 1 : round(n/90) : n;
ii = min(ii,n); % just make sure the last point is ii=length(ix)
plot3(x(ix(ii)),y(ix(ii)),z(ix(ii)))
Or you want evenly distributed?
Thank you!! Okay I didn't try the code yet I will do it tomorrow and update to you. I think it's a bonus if i can make the points evenly distributed too.
[t,r] = cart2pol(x,y);
[~,ix] = sort(t); % sort angle
n = length(ix);
ii = 1 : round(n/90) : n;
ii = min(ii,n); % just make sure the last point is ii=length(ix)
plot3(x(ix(ii)),y(ix(ii)),z(ix(ii)))
this did not work. I want to pick points on plane in a fixed number. not just for plotting.
I think maybe we should edit in the matlab code you gave me.
It's because of this line:
ii = 1 : round(n/90) : n;
If you have mush less than 90 points (round(20/90) = 0)
Try:
clc,clear
t = rand(1,20)*2*pi;
[x,y] = pol2cart(t,1);
plot(x,y,'.b')
hold on
plot(x,y,'color',[1 1 1]/1.1)
[t,r] = cart2pol(x,y);
[~,ix] = sort(t); % sort angle
n = length(ix);
ii = 1 : round(n/20) : n;
ii = min(ii,n); % just make sure the last point is ii=length(ix)
plot(x(ix(ii)),y(ix(ii)))
hold off
[t,r] = cart2pol(x,y);
[~,ix] = sort(t); % sort angle
plot3(x(ix),y(ix),z(ix))
I'm sorry for asking but regarding this code to sort coordinates,
is it working on my data only (circle curves) or is it applicable to all type of freeform curves?
what if the data is not an easy curve (like mine..circle, ) like the body cars and such?
I really appreciate if you can answer this! thank you..
Please show an example
i have new question. should I ask here or open a new question?
it's about the profile curves i already extracted..
profile curves.png
next process i have to fit cubic spline to enable having:
1) smooth curve
2) equal number of curve points for each profile curve
no. 2 is more important to me now.. I tried using curve fitting apps but to no avail.. perhaps i can get some idea from you.
thanks in advance.
You have these curves
profile%20curves.png
And get this surface
surface%20bowl.png
How can you get this surface?
pasu.png
I don't know what is your script about. Can't run it, have no variables
C=[an_x1 an_x2 an_x3 an_x4;
Your codes are so long. I'm just lost. Don't know what to check
Can you be more specific?
Sorry for troubling you with the codes. I'm done with it. I got the results that I wanted. Thanks for your help.
I able to reconstruct the surface from point cloud data using the method I proposed.
But right now, I have a new point cloud data set of a ship hull. More complex object, I want to do the same thing as I did previously which is extracting planes from it. But it seems not working when I used the codes you helped me with.
Attached is my data set.
Appreciate if you can help me.
Can you attach the points for creating the plane you used
p0 = [0 0 0];
p1 = [2 2 2];
p2 = [0 3 3];
but I already change to different points but still the plane are away from the object.
Change this line
% [x0,y0] = meshgrid([min(x(:)) max(x(:))]);
[x0,y0] = meshgrid([min(x(:)) max(x(:))],[min(y(:)) max(y(:))]);
Oh my GOD it works!! so it was a problem of grid?
but how about if I want the plane to change axis? so that the points on plane are like the red dots?
Play with points
p0 = [0 0 0];
p1 = [2 2 2];
p2 = [0 3 3];
plot3(x6,y6,z6)
xlim([min(x) max(x)])
[t,r] = cart2pol(x6,y6);
[~,ix] = sort(t); % sort angle
plot3(x(ix),y(ix),z(ix))
okay this is x,y,z points on one of the planes I extracted.
as previously I want to sort points so I used like what you taught me. But it didn't work.
i want it to connect like this
  • pick points in YZ plane
  • center the data
load x6.mat
load y6.mat
load z6.mat
plot3(x6,y6,z6,'.r')
[t,r] = cart2pol(y6-mean(y6),z6-mean(z6)); % make origin point (0,0) in the center
[~,ix] = sort(t); % sort angle
line(x6(ix),y6(ix),z6(ix))
thank you. the points sorted well. But if I want it to be open curve not closed curve, how do I cut the points?
the bottom connecting line should not be there. Like this
try this trick
I don't think it's working. Only the axes changes, no change in plotting points/line
how to define start point and end point? my plan is to do something like this. I feel like it's going to work
flip axes (YZ ZY)
load x6.mat
load y6.mat
load z6.mat
plot3(x6,y6,z6,'.r')
[t,r] = cart2pol(z6-mean(z6),y6-mean(y6)); % make origin point (0,0) in the center
[~,ix] = sort(t); % sort angle
line(x6(ix),y6(ix),z6(ix))
Thank you so much it works well. I've got so much to learn sorry.
Fatin, can you explain please, how have you done it. i have a cone. i want to extract planes. please guide me.
Dear sir,
I followed your instruction and extract a set of point from my point cloud data. However, my point cloud data is the Lidar scanning of a solid concrete object so the set of extracted points is densed as shown in the attached picture. I want to ask how can I sketch only the boundary of those extracted points? Thank you very much!

Sign in to comment.

More Answers (0)

Asked:

on 1 Oct 2019

Commented:

on 11 Nov 2022

Community Treasure Hunt

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

Start Hunting!