Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Algorithm: point with N distance of a line between two other points

by choocroot (Friar)
on Nov 03, 2010 at 19:48 UTC ( #869299=note: print w/replies, xml ) Need Help??


in reply to Algorithm: point with N distance of a line between two other points

I think that what you really want is the distance of a point to a segment, and not the distance to a line. Because a line is infinite, and the shortest distance of a point to a line might fall outside your segment.

In the case below, the distance of the point C to the line AB is CP. But P is outside of your segment, and what you really want is CA and not CP.

/ x (B) / / / x (C) x (A) `. / `. / `x / (P) / /

So, you must find the coordinate of P (the distance to the line) then check if P is outside of your segment. If it's outside, then you compute CA and CB and take the shortest.

  • Comment on Re: Algorithm: point with N distance of a line between two other points
  • Download Code

Replies are listed 'Best First'.
Re^2: Algorithm: point with N distance of a line between two other points
by japhy (Canon) on Nov 03, 2010 at 20:08 UTC
Re^2: Algorithm: point with N distance of a line between two other points
by DrHyde (Prior) on Nov 04, 2010 at 11:26 UTC

    In fact, I believe that you want ...

    (sort { $a <=> $b } (|CA|, |CB|, |CP|))[1]

    where |...| means "the distance between these points". Of course, because the OP is working with points on a curved surface, he may need to work with great circle distances (and even then he has to allow for the planet not being spherical if he wants to be *really* precise) whereas lots of the solutions you'll find online assume that you're working on a plane. The assumption that the surface is a plane really breaks down once you're talking about distances of more than a few hundred km.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://869299]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-07-03 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?