home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / graphics / 11831 < prev    next >
Encoding:
Internet Message Format  |  1992-11-12  |  1.9 KB

  1. Path: sparky!uunet!know!cass.ma02.bull.com!mips2!news.bbn.com!usc!cs.utexas.edu!sun-barr!ames!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!darwin.sura.net!sgiblab!cs.uoregon.edu!news.uoregon.edu!news.u.washington.edu!ogicse!network.ucsd.edu!pitstop.ucsd.edu!spl
  2. From: spl@pitstop.ucsd.edu (Steve Lamont)
  3. Newsgroups: comp.graphics
  4. Subject: Re: Quickest way to calculate the distance between a point and a line
  5. Keywords: analytic geometry
  6. Message-ID: <1dv3q6INNsgm@network.ucsd.edu>
  7. Date: 13 Nov 92 02:27:18 GMT
  8. References: <BxML0r.II@vuse.vanderbilt.edu>
  9. Organization: University of Calif., San Diego/Microscopy and Imaging Resource
  10. Lines: 39
  11. NNTP-Posting-Host: pitstop.ucsd.edu
  12.  
  13. In article <BxML0r.II@vuse.vanderbilt.edu> brandon@se.vanderbilt.edu(Brandon S. Dewberry) writes:
  14. >I need the quickest algorithm for calculating the distance between a
  15. >point (x,y) and a line f(x).  I will have an initial distance which will be updated at
  16. >each major time slice.
  17. > [...]
  18. >Does anyone have a reference?
  19.  
  20. Yep.  Check in the Analytic Geometry section on straight lines in your
  21. CRC Standard Mathematical Tables handbook.  Mine is the 26th Edition
  22. and the formula is on p. 258.  In other handbooks, it'll probably be
  23. on a different page.
  24.  
  25. For a point P0 to a line through P1 in direction (a,b,c), in C
  26. notation, it's
  27.  
  28.     deltax = x0 - x1;
  29.     deltay = y0 - y1;
  30.     deltaz = z0 - z1;
  31.     term1 = ( ( deltay * c ) - ( deltaz * b ) );
  32.     term1 *= term1;
  33.     term2 = ( ( deltaz * a ) - ( deltax * c ) );
  34.     term2 *= term2;
  35.     term3 = ( ( deltax * b ) - ( deltay * a ) );
  36.     term3 *= term3;
  37.  
  38.     distance = sqrt( ( term1 + term2 + term3 ) / 
  39.             ( ( a * a ) + ( b * b ) + ( c * c ) ) );
  40.  
  41. P0 is (x0,y0,z0) and P1 is (x1,y1,z1).
  42.  
  43.                             spl
  44.  
  45.     
  46.       
  47. -- 
  48. Steve Lamont, SciViGuy -- (619) 534-7968 -- spl@szechuan.ucsd.edu
  49. UCSD Microscopy and Imaging Resource/UCSD Med School/La Jolla, CA 92093-0608
  50. "Far out, man"
  51.             - President George Bush, heard in a stump speech on NPR
  52.