Answer to a question no one asked

James Hurley jhurley at
Fri Jan 7 10:36:58 EST 2005

>Message: 1
>Date: Thu, 6 Jan 2005 16:20:44 -0500
>From: James Steiner <gregortroll at>
>Subject: Re: Answer to a question no one asked
>To: How to use Revolution <use-revolution at>
>Message-ID: <5ec6743205010613203b1ad415 at>
>Content-Type: text/plain; charset=US-ASCII
>On Thu, 6 Jan 2005 07:40:10 -0800, James Hurley
><jhurley at> 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)
>>     else
>>       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.


Glad it was useful. It has a number of applications to problems in geometry.

(To derive this result it is best to use the "Normal" form for the 
straight line. Instead of the standard form, y = m x + b,  the line 
is defined by a perpendicular line from the origin to the straight 
line. The distance from the origin to the line is p and the angle 
this construct makes with the x-axis is phi. Then the line is defined 
by the equation: x cos(phi) + y sin(phi) = p.)

Interesting that you came to RR from LOGO. So did I--or rather from 
LOGO to HC to RR.

Some time ago I wrote a little book, illustrating the use of LOGO to 
solve physics problems--"LOGO Physics", Holt, Rinehart and  Winston.

But I soon learned that students had a much easier time with 
HyperTalk than LOGO, and so I wrote a Turtle Graphics interpreter for 
HT. You can find in on the RR web site: or for download:


More information about the Use-livecode mailing list