6

I need to find the distance of multiple points to a curve of the form: f(x) = a^(k^(bx))

My first option was using its derivative, using a line of the form with the inverse of the derivative, giving it coordinates of the Point and intersecting it with the original curve. Finally, we calculate the distance between points with simple geometry.

That's the mathematical process that I usually follow. I need to save time (since I'm doing a genetic algorithms program) so I need an efficient way to do this. Ideas?

Ph0en1x
  • 9,943
  • 8
  • 48
  • 97
OFRBG
  • 1,653
  • 14
  • 28
  • I think you're on the right path by using the derivative, but since a true derivative could get difficult in code, you could fake it and compute the slope of the tangent line by computing a short sample line between the points (x, f(x)) and (x+h, f(x+h)) where h is some tiny value. The genetic part could be making h smaller and smaller as needed. – Brett Forsgren - MSFT Jan 25 '13 at 22:33

2 Answers2

4

The distance between a point (c,d) and your curve is the minimum of the function

sqrt((c-x)^2 + (d-a^(k^(bx)))^2)

To find its minimum, we can forget about the sqrt and look at the first derivative. Find out where it's 0 (it has to be the minimal distance, as there's no maximum distance). That gives you the x coordinate of the nearest point on the curve. To get the distance you need to calculate the y coordinate, and then calculate the distance to the point (you can just calculate the distance function at that x, it's the same thing).

Repeat for each of your points.

The first derivative of the distance function, is, unfortunately, a kind of bitch. Using Wolfram's derivator, the result is hopefully (if I haven't made any copying errors):

dist(x)/dx = 2(b * lna * lnk * k^(bx) * a^(k^(bx)) * (a^(k^(bx)) - d) - c + x)
zmbq
  • 38,013
  • 14
  • 101
  • 171
  • if the amount of points will be high (using floats for example) using your method isn't possible because of calculation complexity. Just brutforcing all the dot's id impossible if you have a lot of dots. – Ph0en1x Jan 25 '13 at 22:41
  • @zmbq You mean taking the first derivative of (c-x)^2 + (d-a^(k^(bx)))^2 ? I then find where the derivative is equal to 0, which will give me an x, right? Not the distance itself. I need to re-input the x in the original equation and compute, true? – OFRBG Jan 25 '13 at 22:49
  • If he needs the distance between all the points and the curve, I don't believe he has a choice. – zmbq Jan 25 '13 at 22:49
  • 1
    @Fiire, yes, exactly. I'll elaborate. – zmbq Jan 25 '13 at 22:50
0

To find distance from point to curve it's not a simple task, for that you need to find the global of function enter image description here where f(x) is the function which determine your curve.

For that goal you could use:
Simplex method
Nelder_Mead_method
gradient_descent

This methods implemented in many libraries like Solver Foundation, NMath etc.

Ph0en1x
  • 9,943
  • 8
  • 48
  • 97