home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!purdue!news.cs.indiana.edu!nstn.ns.ca!news.ucs.mun.ca!cs.mun.ca!garfield.cs.mun.ca!rodney
- From: rodney@garfield.cs.mun.ca (Rod Hutchings)
- Subject: Re: Need: prpndcular dist from pt to line
- Message-ID: <1992Dec30.192343.22357@cs.mun.ca>
- Sender: usenet@cs.mun.ca (NNTP server account)
- Organization: CS Dept., Memorial University of Newfoundland
- References: <1992Dec29.210554.5350@seas.gwu.edu>
- Date: Wed, 30 Dec 1992 19:23:43 GMT
- Lines: 53
-
- In article <1992Dec29.210554.5350@seas.gwu.edu> ilan@seas.gwu.edu (Ilan Berkner) writes:
- >
- >Given a line, or line segment (I can do both), I need to find the
- >distance from a point (that may or may not be on the line) to that line.
- >If the point is on the line, then the distance is zero, obviously.
- >
- >I know the endpoints of the line segment in cartesian space, and I also
- >know the slope and intercept, and the coordinates of the point.
- >
- >This is for a computer application, so anything involving integer math
- >is preferable to floating-point.
- >
- >Thanx very much in advance. I know this is almost a trivial problem
- >for all you math geniuses out there, but I also want to make sure that
- >whatever solution I get, is also the best.
-
- If you have the slope and intercept of the line then you can write it
- as y = mx + b where m is the slope and b is the intercept. This can be
- converted to the form
- ax + by + c = 0
- by writing the equation y = mx + b as mx - y + b = 0.
-
- Now there is a general formula for the distance from the point (x0,y0) to
- the line Ax + By + C = 0. It goes as follows:
-
- d = abs(A*x0 + B*y0 + C) / sqrt(A^2 + B^2)
-
- where (1) the coordinates of the point are put into the equation of the line
- for x and y, (2) the coefficients of x and y are squared and summed, then
- the results of (1) and the square root of (2) are divided out.
-
- In this case we substitute A = m, B = -1, and C = b to give the form as
- follows:
-
- d = abs(m*x0 - y0 + b) / sqrt(m^2 + 1)
-
- This will give the required distance, and can be easily implemented on a
- computer.
-
- --
- regards,
- the Rodster
- rodney@garfield.cs.mun.ca
-
- "Give the Clown credit, he beats up cowboys AND Indians."
- - Christopher Robin Zimmerman
- (A fellow poster to rec.sport.pro-wrestling)
-
- --
- --
- regards,
- the Rodster
- rodney@garfield.cs.mun.ca
-