home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / sci / math / 17532 < prev    next >
Encoding:
Text File  |  1992-12-30  |  2.3 KB  |  65 lines

  1. Newsgroups: sci.math
  2. 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
  3. From: rodney@garfield.cs.mun.ca (Rod Hutchings)
  4. Subject: Re: Need: prpndcular dist from pt to line
  5. Message-ID: <1992Dec30.192343.22357@cs.mun.ca>
  6. Sender: usenet@cs.mun.ca (NNTP server account)
  7. Organization: CS Dept., Memorial University of Newfoundland
  8. References: <1992Dec29.210554.5350@seas.gwu.edu>
  9. Date: Wed, 30 Dec 1992 19:23:43 GMT
  10. Lines: 53
  11.  
  12. In article <1992Dec29.210554.5350@seas.gwu.edu> ilan@seas.gwu.edu (Ilan Berkner) writes:
  13. >
  14. >Given a line, or line segment (I can do both), I need to find the 
  15. >distance from a point (that may or may not be on the line) to that line.
  16. >If the point is on the line, then the distance is zero, obviously.
  17. >
  18. >I know the endpoints of the line segment in cartesian space, and I also
  19. >know the slope and intercept, and the coordinates of the point.
  20. >
  21. >This is for a computer application, so anything involving integer math
  22. >is preferable to floating-point.
  23. >
  24. >Thanx very much in advance.  I know this is almost a trivial problem
  25. >for all you math geniuses out there, but I also want to make sure that
  26. >whatever solution I get, is also the best.
  27.  
  28. If you have the slope and intercept of the line then you can write it
  29. as y = mx + b where m is the slope and b is the intercept.  This can be 
  30. converted to the form 
  31.     ax + by + c = 0
  32. by writing the equation y = mx + b as mx - y + b = 0.  
  33.  
  34. Now there is a general formula for the distance from the point (x0,y0) to 
  35. the line Ax + By + C = 0.  It goes as follows:
  36.  
  37.         d = abs(A*x0 + B*y0 + C) / sqrt(A^2 + B^2)      
  38.  
  39. where (1) the coordinates of the point are put into the equation of the line
  40. for x and y, (2) the coefficients of x and y are squared and summed, then
  41. the results of (1) and the square root of (2) are divided out.
  42.  
  43. In this case we substitute A = m, B = -1, and C = b to give the form as
  44. follows:
  45.  
  46.         d = abs(m*x0 - y0 + b) / sqrt(m^2 + 1)      
  47.  
  48. This will give the required distance, and can be easily implemented on a
  49. computer.
  50.  
  51. --
  52. regards,
  53. the Rodster
  54. rodney@garfield.cs.mun.ca
  55.  
  56. "Give the Clown credit, he beats up cowboys AND Indians."
  57.                 - Christopher Robin Zimmerman 
  58.                 (A fellow poster to rec.sport.pro-wrestling)
  59.  
  60. -- 
  61. --
  62. regards,
  63. the Rodster
  64. rodney@garfield.cs.mun.ca
  65.