In Matlab I've got two matrices,L1 and L2, containing in each row the coordinates (row, column) of several points in 2D space:
L1=[1,1;2,2;3,3];
L2=[4,4;5,5;6,5;7,6;8,7];
After plotting I've got this:

I'm trying to implement an algorithm that could fusion lines that are similarly orientated. I've tried for quite a while. I guess that the simplest way of solving this is to follow these steps:
-First: suppose that L1 and L2 are two segments of the same line(L3).
-Next: Starting from (1,1) (or (8,7)) evaluate the orientation of the next point. In other words, the orientation that point (2,2) has from (1,1), point (3,3,) from (2,2), etc. And save those values.
-Next: Calculate from all orientation values the average value.
-Next: evaluate if the fusion points between fibers, that in this case are (3,3) and (4,4), follow a similar orientation.
-Results: If previous stage is TRUE, then fusion the fibers. If FALSE, do nothing.
One key point here is to establish a reference from which orientation angles can be measured. Maybe this approach is too complicated. I guess there is a simpler way and less memory consuming way. Thank you.