Answer to a question no one asked
gregortroll at gmail.com
Thu Jan 6 16:20:44 EST 2005
On Thu, 6 Jan 2005 07:40:10 -0800, James Hurley
<jhurley at infostations.com> wrote:
> What is the perpendicular distance between a point and a line?
> Application for which there is no redeeming social value:
> if x3-x2 is 0 then
> return (x1-x2)
> put (y3-y2)/(x3-x2) into m -- The slope
> return (m*(x1-x2)-(y1-Y2))/sqrt(1+m*m)
> end if
Oddly, this is the answer to a question I asked on another users list
for another programming environment, months ago -- netlogo-users.
For a drawing utility, I needed to create a query that returns the set
of "patches" (grid cells) with a perpendicular distance of N from the
line between two arbitrary cells.
Using your formula, I can now use this (netlogo) code:
set line-patches ( patches with [ ( perpdist myself start-point
end-point ) < n ]
The prior solution was extremely verbose, convoluted, and slow. This
seems like it will be faster.
More information about the Use-livecode