Fragemented linear feature alignment technique

62 Views Asked by At

I am having set of linear features lie on a plane (it does not a matter whether the pane is vertical or horizontal). all linear features are either parallel or othogonal to the vertical axis or to horizontal axis (see figure). I want to align vertical line segments which are collinear. As I am having many fragmented lines at every where i want some specific theory / concept to follow to build a technique.

Note: I know end point coordinates of each line segment.

can any one suggest a way.

i am not sure to which field, i should post this.

enter image description here

1

There are 1 best solutions below

1
On BEST ANSWER

I would do the following.

  1. Accept the list of line segments with coordinates $\left\{(x_{ij},y_{ij})\right\}_{i=1}^N$ with $j \in \{1,2\}$.
  2. Compute their slopes $m_i$ and offsets $b_i$ as follows. The line through two points $(x_1,y_1),(x_2,y_2)$ has the equation $y = mx+b$ for $$m = \frac{y_2-y_1}{x_2-x_1}, \quad b = y_1 - m\cdot x_1$$ At this point, for each line segment, you will have calculated slope and offset.
  3. Two line segments are parallel if they have the same slope. They are collinear if they have the same slope and the same intercept.

    So I would sort the sequence by slope, and then by the intercept. All slopes within a predefined small tolerance $\epsilon_m$ will be considered the same, and all intercepts within some (possibly larger) tolerance $\epsilon_b$ will be considered the same. Based on that, go through the sorted list, checking if consecutive elements are within the allowed tolerance of each other, and output the groups once you find them.