Re: distance between two 2D curves



Sven wrote:
Dave Bell <dbell@xxxxxxxxxxxxxxxxxxxx> wrote in message
<lmsAi.287$Sd4.281@xxxxxxxxxxxxxxxxxxxx>...
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.

Oh, that's easy. No, wait, sorry, it's not. ;)

LOL.

Sven, thanks for the suggestion. I really need to learn to think in vectors more for Matlab. I think in vectors on paper, but somehow haven't made the transition to vectorized code.


Sorry, I hadn't considered the 'curve fitted from points'
aspect of any of this either... I haven't really worked
much with fitted curves in matlab, but would it be possible
to just resample the fitted curve and generate 'X' new
points on the line? This way you could just use the method
above, and your accuracy would be a function of how large
you made X.

That's kind of how I was thinking of it originally. For my specific situation, I don't think I'll need the precision that would require multiple interpolations (resampling) of the curve data. I think I have enough data points already that I could just find the closest pre-existing point.

Cheers,
Sven.


-KC
.



Relevant Pages

  • 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... ... Then the distance would just be ... 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 points? ...
    (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: IGES problem-the imported open curves
    ... I can import the curve data to solidwork and make a loft-surface. ... Now I know that he could loft ...
    (comp.cad.solidworks)

Loading