home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / graphics / 11955 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.2 KB

  1. Path: sparky!uunet!wupost!gumby!yale!yale.edu!spool.mu.edu!sgiblab!munnari.oz.au!uniwa!watson
  2. From: watson@maths.uwa.oz.au (David Watson)
  3. Newsgroups: comp.graphics
  4. Subject: Re: Point inside a triangle
  5. Date: 17 Nov 1992 02:05:00 GMT
  6. Organization: The University of Western Australia
  7. Lines: 34
  8. Message-ID: <1e9k0cINNc0q@uniwa.uwa.edu.au>
  9. References: <7bv1svg@rpi.edu> <BxsLL1.5H5@slipknot.rain.com> <1992Nov16.115211.23169@sophia.smith.edu> <1e9c3cINN4hi@uniwa.uwa.edu.au>
  10. NNTP-Posting-Host: madvax.maths.uwa.oz.au
  11.  
  12. watson@maths.uwa.oz.au (David Watson) writes:
  13.  
  14. >A fail-proof method is to compute the barycentric coordinates.  For a
  15. >triangle {(x1,y1), (x2,y2), (x3,y3)} and some point (x0,y0), calculate
  16.  
  17. >b0 = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)
  18. >b1 = ((x2 - x0) * (y3 - y0) - (x3 - x0) * (y2 - y0)) / b0 
  19. >b2 = ((x3 - x0) * (y1 - y0) - (x1 - x0) * (y3 - y0)) / b0
  20. >b3 = ((x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0)) / b0 
  21.  
  22. >Then if b1, b2, and b3 are all > 0, (x0,y0) is strictly inside the
  23. >triangle; if bi = 0 and the other two coordinates are positive, (x0,y0)
  24. >lies on the edge opposite (xi,yi); if bi and bj = 0, (x0,y0) lies on
  25. >(xk,yk); if bi < 0, (x0,y0) lies outside the edge opposite (xi,yi);
  26. >if all three coordinates are negative, something else is wrong.  This
  27. >method does not depend on the cyclic order of the vertices.
  28.  
  29. and if b0 == 0 => (x1 == x2 && x1 == x3 && y1 == y2 && y1 == y3)
  30.  
  31. that is, if b0 = 0 then you have an empty triangle because all
  32. three vertices are coincident.  That is because
  33. fabs(b0) / 2 is the area of the triangle and b1, b2, and b3,
  34. before division by b0, are similarly related to the areas of the
  35. subtriangles defined by (x0,y0) and each pair of the other three
  36. points.  Notice that b1 + b2 + b3 = 1 always so if bi is > 0 the
  37. others will compensate, and not all three can be negative.
  38. If b1 = b2 = b3 then (x0,y0) is at the centroid (center of gravity)
  39. of the triangle, x0 = (x1 + x2 + x3) /3, and y0 = (y1 + y2 + y3) /3.
  40.  
  41. --
  42. Dave Watson                          Internet: watson@maths.uwa.edu.au
  43. Department of Mathematics            
  44. The University of Western Australia               Tel: (61 9) 380 3359
  45. Nedlands, WA 6009  Australia.                     FAX: (61 9) 380 1028
  46.