How can the plot be divided into 2 using the graph line?

Hello everyone,
I have a graph that I obtained with the help of the RRT algorithm.
In addition, I have an array of points that are on the plot as you can see.
I want to write a function \ use a classification algorithm (or any other machine learning algorithm) to divide the points into 2 using the graph (points on the right side of the graph and points on the left side)
How can this be done? I tried several options but failed.. :/
I would be very happy to help! :)

 Réponse acceptée

Matt J
Matt J le 2 Nov 2023
Modifié(e) : Matt J le 2 Nov 2023
Perhaps something like the following:
load roadPoints
[X,Y]=ndgrid(0:2.5:100);
p1=polyshape([roadPoints;min(roadPoints(:,1)), max(roadPoints(:,2))],'Simplify',true);
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
p2=polyshape([roadPoints;max(roadPoints(:,1)), min(roadPoints(:,2))],'Simplify',true);
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
class1=isinterior(p1,X(:),Y(:));
class2=isinterior(p2,X(:),Y(:));
noclass=~(class1|class2);
hold on
scatter(X(class1), Y(class1),'g','filled','MarkerEdgeColor','none');
scatter(X(class2), Y(class2),'c','filled','MarkerEdgeColor','none');
scatter(X(noclass),Y(noclass),'MarkerFaceColor',[0.5,0.5,0.5],'MarkerEdgeColor','none')
plot(roadPoints(:,1), roadPoints(:,2),'r','LineWidth',5);
legend('Class 1', 'Class 2','UnClassified','Location','NorthOutside')
hold off

5 commentaires

It looks great!! I will try it now
Thank you very much!! :))))
You're welcome, but please Accept-click the answer if you decide it is what you need.
Hi,
If the route looks like this, the classification of the points is not done correctly..
The calssification shouls be like this:
Thanks for your help! :)
I fix it!
thanks! <3
I'm glad, but agan, please Acept-click the answer if it ultimately worked.

Connectez-vous pour commenter.

Plus de réponses (2)

Matt J
Matt J le 29 Oct 2023
Perhaps you can find the nearest point on the boundary line with pdist2, then make a decision based on whether the nearest point is to the right or to the left.

2 commentaires

There is no algorithm that takes the output of a map and classifies the points using the line on the map?
Matt J
Matt J le 29 Oct 2023
Modifié(e) : Matt J le 29 Oct 2023
Didn't I just propose one?

Connectez-vous pour commenter.

It looks like all the points on the right have a y value greater than about 6, so just do
rightIndexes = (y >= 6);
xRight = x(rightIndexes);
yRight = y(rightIndexes);
xLeft = x(~rightIndexes);
yLeft = y(~rightIndexes);

3 commentaires

Hey,
Every time I get a different random route. Therefore I cannot say y>6
Is there another way?
Is the route completely random or can a relation/observation be identified?
And you have not defined what is the criteria/logic to be used for dividing points to the left and right side.
I get the route from the RRT algorithm and I later turn it into a discrete route.
Basically, my goal is to build a walking track for a 2-legged robot that can only step in places where there are dots.
I want to create a track for each leg (for the right leg and the left leg)
That's why I want to choose each time 2 points from each side of the track that are closest to the center point of the body (the point of the track is RRT)

Connectez-vous pour commenter.

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by