1
votes

I need to calculate some kind of distance between to curves.

Those are general curves, and may not be functions - that is, some values of x may be mapped to more then one value.

EDIT

  • The curves are given as a list of X,Y pairs and the logical curve is the line passing through all the points in the order given. a typical data set will include about 1000 points

  • as noted, the curve may not be a function, but is usually similar to a function

This issue us what prevents using interp1 or the curve fitting toolbox (in Matlab)

The distance measure I was thinking of the the area of the region between the curves - but any reasonable alternative is ok.

EDIT a sample illustration of to curves, and the area I want to compute Curves

A Matlab solution is preferred, but other languages are also fine.

2
The reason the exact distance measure isn't critical is that it's used as an error function. As long as I can calculate an empirical threshold based on results that are close enough, I don't care about the exact functionOphir Yoktan
Yes, but have not yet even told us enough information to provide anything constructive to you.user85109

2 Answers

2
votes

If you have functions that are of the type y = f(x) and they are defined over the same domain, then a common way to find the "distance" is to use the L2 norm as explained here http://en.wikipedia.org/wiki/L2_norm#p-norm. This is simply the integral of the absolute value of the difference between the functions squared. If you have parametric curves then you cannot directly employ this approach. If the L2 norm is not good enough for your requirements then you will need to provide a more concrete definition of what you mean by "distance". If you are unclear as to what you need try taking a look at different types of mathematical norm and see if any of the commonly used ones are what you need (ie L1 norm, uniform norm). The wikepedia link above is a good start point. If the L2 is good enough then you need a way to calculate the integral that you have - there are many many numerical integration techniques out there and I suggest google is your friend here (or a good numerical analysis text book).

If you do have parametric type curves then this is very nontrivial. Using the "area" between curves is not a good idea as there is no clear way to define this area and would become even more complicated in the general case where you could have self-intersecting curves. If your curves are parametrized in the same way you could try some very crude measurement where you evaluate points on each curve at equally spaced values over the parameter range, then calculate the length of the distance between each, sum and take the average as a notion of "closeness". i.e. partition your parameter range into a set {u_0, ... , u_n} and evaluate curve1(u_i) and curve2(u_i) for each i to generate a set of n paired points. Then sum the euclidean distances between each pair of points.

This is very very crude though and if the parametrizations are different then it wont be much use.

0
votes

You need to define what you mean by distance between the curves. If it is the closest approach between two general curves, then it becomes quite difficult to solve the problem.

If the "curves" are not even representable as single valued functions of x, then it becomes more complex yet.

Merely telling us that you need to define "some kind of distance" is too broad of a statement to be on-topic here, and it says that you have not yet thought out the problem you wish to solve.

If all you are willing to tell us is that the curves are two totally general parametric curves, which may be closed or not, or they may not even lie over the same domain, then the question becomes so totally ill-posed as to be impossible to answer. What is the area between two curves in that case?

If the curves are defined over the SAME support, then subtracting them and integration of the absolute value or square of the difference will be adequate. But you have already told us that these "curves" may be multi-valued. In that case, it is essentially impossible to do what you are asking.