From: Frédéric Bergeron on
Hi all,

I am programming a gui for leveling fields, and now I want to divide the field into multiple sections. For those divisions, I want to define some lines that pass throught a set a points that I have found on my field. Those points are found by a local minimum and maximum analysis of my fields. So I want my divisions lines to pass throught those points.

PROBLEM:
My problem is that I do not know how much I will have division lines at the end, so I want to program an algorith that will work for any set of points. For example, if my x and y values of my points are:
x=[1,1,1.5,1.5,2,3,3,4,5,6];
y=[5,8,6,7,1,2,3,3,5,6];
plot(x,y,'b*');
axis([0 10 0 10]);

I want that my program "detect" that there are 2 lines in this plot: a vertical one at x=1,25 and an oblic one that have an equation of about y=1.2*x-1.25 , i.e.:
x_lines={1.25*ones(1,10),1.5:0.5:8};
y_lines={4:(9-4)/9:9,1.2*x_lines{2}-1.25};
for n=1:length(x_lines)
plot(x_lines{n},y_lines{n},'r-'); hold on;
end

WHAT I'VE DONE SO FAR:
First, I tried to separate my points by grouping together the points that are close to each other (i.e group together the points that are distant of a maximum distance to any other points, but sometimes the 2 "groups" of points are close to each other too. So in this case this will have only one groups of points, wich is not what I want.

Second, I tried to generate a lot of "testing lines" from a lot of points in my axes. Those "testing lines" where defined by 2 points: a starting point that can be any point of the axe, an a finish point defined from the starting point so that there was 8 "testing lines" around each starting points. After, I verified if any of the points were close enough to those testing lines, and keep only the lines that have a minimum of point near of them. But this method was way too long for Matlab and too much lines were selectionned at the end.

So I'm now searching for another way to find the two red lines plotted previously, in an automatic way. I tought I may use lsqlin and search for an minimum resnorm output, but I don't really know how to code that.

Have anybody have an idea? I would truly appreciate it.

Fred