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

  1. Xref: sparky comp.programming:3066 sci.physics:18154 sci.math:14413
  2. Newsgroups: comp.programming,sci.physics,sci.math
  3. Path: sparky!uunet!gatech!hubcap!mark
  4. From: mark@hubcap.clemson.edu (Mark Smotherman)
  5. Subject: area in closed curve; similar to net work calculation
  6. Message-ID: <1992Nov5.132626.21379@hubcap.clemson.edu>
  7. Organization: Clemson University
  8. Date: Thu, 5 Nov 1992 13:26:26 GMT
  9. Lines: 41
  10.  
  11.  
  12. I want to get a reference to the first use/publication of an algorithm
  13. to find the area within a discretized closed curve.  While CAM is the
  14. application for which I came up with the algorithm, I later found the
  15. same type of problem as a net work calculation for a heat engine in
  16. a freshman physics text (figure 19-8, Sears and Zemansky, University
  17. Physics, 4th ed., 1970, p. 271).  So I expect this algorithm has been
  18. around for quite a while.
  19.  
  20. Given a closed curve completely described by unit movements LRUD (left,
  21. right, up, and down), calculate the enclosed area.  The description
  22. may be clockwise or counterclockwise and of arbitrary shape.
  23.  
  24.  
  25. area = 0;
  26. counter = ARBITRARY_VALUE;  /* makes more sense visually if it is large */
  27.                             /* enough so that counter never goes negative */
  28. while( moves_are_left() ){
  29.     move = next_move();
  30.     switch(move){
  31.         case L:
  32.             area = area - counter;
  33.             break;
  34.         case R:
  35.             area = area + counter;
  36.             break;
  37.         case U:
  38.             counter = counter + 1;
  39.             break;
  40.         case D:
  41.             counter = counter - 1;
  42.             break;
  43.     }
  44.     area = abs(area);
  45.  
  46.  
  47. Please email me directly.  I don't regularly read some of the cross-posted
  48. groups.  Thanks.
  49. -- 
  50. Mark Smotherman, CS Dept., Clemson University, Clemson, SC 29634-1906
  51.   (803) 656-5878,  mark@cs.clemson.edu  or  mark@hubcap.clemson.edu
  52.