views:

39

answers:

2

I need an algorithm to calculate, numerically, the degree of similarity between two drawn lines. The lines are drawn using a mouse, and are stored as a set of cartesian coordinates before being filtered and smoothed using separate algorithms.

For example, within the following diagram: diagram

Lines A and B are clearly similar, but B and C are not. The algorithm should reflect this. Additionally, the 'direction' of the line, as indicated by the start and end points, matters. Does such an algorithm already exist?

A: 

Take a look at the Hough transform. This may be overkill, perhaps someone else has a better solution.

Ivo
A: 

A naive approach can be taking the sum of the distances between the corresponding points on the two lines.So lets assume both of the lines are of almost same length and the number of points on the lines are approximately same and equidistant.
1.Translate the line 2 so that its start point is same as line 1's starting point.
2. calculate the sum of distances between corresponding points between line 1 and line2.
3. If average distance (i.e. SUM/NUMBER_OF_POINTS) is lesser than the THRESHOLD then lines are similar otherwise they are different.
This can be extended to support lines with different sizes. In that case, just enlarge the smaller line to match up to the longer line, then rest can be similar to the above approach.
Apart from calculating the distance you can calculate the difference of the slopes of the lines and if different in slopes at any point (or few points, you need to some experiment for this) is way to high (above than some THRESHOLD) then they are not similar.

bhups