"be consistent" 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 Need Help??

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

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.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://869299]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found