Re: distance between two 2D curves



Sven wrote:
KC <kc_news@xxxxxxxxx> wrote in message
<x_pAi.5842$u21.742@trnddc08>...
KC wrote:
I need to calculate the shortest distance from a (known)
point on one
curve, to another curve. Each curve is defined by two
column vectors of
data.

Any ideas? All I can think of is a distance between two
points, which
is easy, but how to define the second point to be the
point which is
closest to the first (known) point?

Thanks,

-KC
Oh, and each curve is made up of ~1000 points... so
checking each point
in curve2 with some sort of for/if loop seems quite
inefficient.

Well, if your first point is known, you can ignore that it
comes from a curve and just think about finding the closest
point in a set to your test point (its x and y coordinates).
You're right that this will be slightly inefficient in a
loop, but I think you can do it with just some vector
calculations. I'll assume that you're working in 2d (just x
and y vectors representing coordinates of your set of points).
Then the distance (using Pythagora's) would just be
something like:

distVector = sqrt((xVec-ptx).^2 + (yVec-pty).^2);

And then you can just find the minimum of this vector.

[minDist, ptIndex] = min(distVector);

2 lines and no loop required.

Cheers,
Sven.

Straight-forward, simple, and fast, I agree.
But that finds the closest point out of a predetermined set.

How would he find the closest point on a curve (fit to some TBD equation) through those (x,y) points?

Then the next step would be to find the closest pair of arbitrary points on the two (TBD fit) curves.

Dave
.



Relevant Pages

  • Re: distance between two 2D curves
    ... You need to drop a perpendicular (shortest distance) between the known point ... for each point on the curve. ... the distance from your point to each of the segments constituting the ... and then pick the closest one. ...
    (comp.soft-sys.matlab)
  • Re: Pls help Curve ftting
    ... Consider any point with a nearby curve. ... distance between curve and data points, ... each value of y in your data, the HORIZONTAL distance ... to the closest point on the curve is minimized. ...
    (comp.soft-sys.matlab)
  • Re: Distance between a point and y = ax^2 + bx + c
    ... consists of all points for which, if you plug in r for x, you ... Plugging 0 gives you the constant term. ... curve. ... The closest point will be the one with the ...
    (sci.math)
  • Re: Fitting an exponential sinusoid with fixed length linear elements?
    ... Given a point on some curve in the plane, ... find the closest solution closest in x) to the ... choosing the closest root in one ... an interpolant with fixed length segments? ...
    (comp.soft-sys.matlab)
  • Re: distance between two 2D curves
    ... and each curve is made up of ~1000 points... ... But that finds the closest point out of a predetermined set. ... to just resample the fitted curve and generate 'X' new ... I don't think I'll need the precision that would require multiple interpolations of the curve data. ...
    (comp.soft-sys.matlab)

Loading