home *** CD-ROM | disk | FTP | other *** search
- 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
- From: spl@pitstop.ucsd.edu (Steve Lamont)
- Newsgroups: comp.graphics
- Subject: Re: Quickest way to calculate the distance between a point and a line
- Keywords: analytic geometry
- Message-ID: <1dv3q6INNsgm@network.ucsd.edu>
- Date: 13 Nov 92 02:27:18 GMT
- References: <BxML0r.II@vuse.vanderbilt.edu>
- Organization: University of Calif., San Diego/Microscopy and Imaging Resource
- Lines: 39
- NNTP-Posting-Host: pitstop.ucsd.edu
-
- In article <BxML0r.II@vuse.vanderbilt.edu> brandon@se.vanderbilt.edu(Brandon S. Dewberry) writes:
- >I need the quickest algorithm for calculating the distance between a
- >point (x,y) and a line f(x). I will have an initial distance which will be updated at
- >each major time slice.
- > [...]
- >Does anyone have a reference?
-
- Yep. Check in the Analytic Geometry section on straight lines in your
- CRC Standard Mathematical Tables handbook. Mine is the 26th Edition
- and the formula is on p. 258. In other handbooks, it'll probably be
- on a different page.
-
- For a point P0 to a line through P1 in direction (a,b,c), in C
- notation, it's
-
- deltax = x0 - x1;
- deltay = y0 - y1;
- deltaz = z0 - z1;
- term1 = ( ( deltay * c ) - ( deltaz * b ) );
- term1 *= term1;
- term2 = ( ( deltaz * a ) - ( deltax * c ) );
- term2 *= term2;
- term3 = ( ( deltax * b ) - ( deltay * a ) );
- term3 *= term3;
-
- distance = sqrt( ( term1 + term2 + term3 ) /
- ( ( a * a ) + ( b * b ) + ( c * c ) ) );
-
- P0 is (x0,y0,z0) and P1 is (x1,y1,z1).
-
- spl
-
-
-
- --
- Steve Lamont, SciViGuy -- (619) 534-7968 -- spl@szechuan.ucsd.edu
- UCSD Microscopy and Imaging Resource/UCSD Med School/La Jolla, CA 92093-0608
- "Far out, man"
- - President George Bush, heard in a stump speech on NPR
-