I have several vector paths and a query path and now I am trying to get the path which is most similar to the query path. I can access length(perimeter) of each path, and width and height of their bounding boxes. I am using python and using pyx library for rendering SVG paths and calculating their bounding boxes. Pseudo code looks like...
THRESHOLD = //some value
qpath = //my query path
similar_paths = []
for path in path_list:
if (comparable width and comparable height and comparable perimeters):
similar_paths.append(path)
But It does not seem to give nice results. Any ideas on how to improve the results?
Lets use a simple PyX graph to generate some paths:
The paths could also come from an SVG file read in parsed mode.
Once you have PyX paths, you can use PyX features to get further information about the paths. In the following simple version I calculate a few points along each path and the sum up their distance. (I do it using method names ending by
_pt
, which work in PostScript points. It is a little faster than using PyX units. Also I converted all paths to normpaths explicitely in the beginning. While this is not necessary, it helps reduces some function calls internally.)Here is the full code (including the graph to generate the sample paths):
The program just prints out:
which indicates, that the dashed lines is closer to the solid one than the dotted line.
You may also compare tangents, curvatures, the arclen itself etc. ... there are plenty of options depending on your needs.