home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l4p150 < prev    next >
Text File  |  1990-07-15  |  4KB  |  87 lines

  1.        ╔════════════════════════════════════════════════════╗
  2.        ║ Lesson 4 Part 150  F-PC 3.5 Tutorial by Jack Brown ║
  3.        ╚════════════════════════════════════════════════════╝
  4.  
  5.              ┌────────────────────────────────┐
  6.              │   Polygon Property Case Study  │
  7.              └────────────────────────────────┘
  8.  
  9. A practical case study which involves the calculation of the properties
  10. of polygons in the x-y plane that are specified by the coordinates of
  11. their vertices.  The complete program can be found in the file
  12. JBPOLY1.SEQ which will form part of Lesson 4.  The descriptive part
  13. of the algorithm for computing the area of a polygon based on its x-y
  14. coordinates is presented below.
  15.  
  16. \ Original Date: November 4, 1985
  17. \ Last Modified: January 2, 1989
  18. \ Author:        Jack W. Brown
  19. \ File name:     JBPOLY1.SEQ
  20. \ Function:      Computes Area of a Polygon given the x,y
  21. \                coordinates of its verticies
  22.  
  23. \ The following mathematical algorithm is often used to
  24. \ determine the area of cross-section provided it can be
  25. \ represented adequately by a finite number of straight line
  26. \ segments (this is almost always possible).  The technique
  27. \ can also be applied to cross-sections with holes by moving
  28. \ around the hole in a counter clockwise direction and traversing
  29. \ to and from the hole along the same path.
  30.  
  31. \ The general algorithm.
  32.  
  33. \     p1 /---------\  p2        p1 = ( x1,y1 )
  34. \       /           \           p2 = ( x2,y2 )
  35. \      /             \  p3      p3 = ( x3,y3 )
  36. \     /              /          p4 = ( x4,y4 )
  37. \ p5 /--------------/ p4        p5 = ( x5,y5 )
  38. \
  39. \ AREA OF THE POLYGON =
  40. \ [(x1y5-x5y1)+(x2y1-x1y2)+(x3y2-x2y3)+(x4y3-x3y4)+(x5y4-x4y5)]/2
  41. \ In general:
  42. \            i=n
  43. \ AREA = 0.5*SUM [ x(i)y(i-1) - x(i-1)y(i) ]
  44. \            i=1
  45. \  where we define x0 to be x5 and y0 to be y5.
  46.  
  47. \ Example without a hole.
  48. \  X   Not drawn to scale!!
  49. \  |                              p1 = ( 8,4 )
  50. \  |                              p2 = ( 6,1 )
  51. \  |    p4 ----------- p1         p3 = ( 2,1 )
  52. \  |      /          /            p4 = ( 5,4 )
  53. \  |     /          /
  54. \  |    /          /
  55. \  | p3 -----------  p2
  56. \  |-----------------------Y
  57.  
  58. \ A = [(8*4-5*4)+(6*4-8*1)+(2*1-6*1)+(5*1-2*4)]/2 = 10.5
  59.  
  60.  
  61. \ Example of a polygon with a hole removed
  62. \ Sorry but the diagram below is not to scale.   units= centimeters
  63. \       Y
  64. \ p9 ---|-------------------------------- p1     p1 = (6,5)
  65. \    \  |   p5            p4            /        p2 = (2,0) = p8
  66. \     \ |     +----------+            /          p3 = (3,3) = p7
  67. \      \|     |cut out   |          /            p4 = (3,4)
  68. \       \     +----------+        /              p5 = (1,4)
  69. \       |\  p6         p7,p2    /                p6 = (1,3)
  70. \       | \                   /                  p7 = (3,3)
  71. \       |   \               /                    p8 = (2,0)
  72. \       |     \           /                      p9 = (-1,5)
  73. \       |       \       /
  74. \       |         \   /
  75. \       |          \/  p8,p2
  76. \    ---+-------------------------- X
  77. \
  78. \  Traverse outside clockwise and the cut out counter clockwise.
  79. \  A = [(6*5-(-1)*5)+(2*5-6*0)+(3*0-2*3)+(3*3-3*4)+(1*4-3*4)
  80. \                   +(1*4-1*3)+(3*3-1*3)+(2*3-3*0)+(-1*0-2*5)]/2
  81. \  A = 15.5 sq cm
  82.  
  83. \ Thoroughly study the above algorithm and sample calculations until
  84. \ you are convinced that they are valid and that they will work!
  85.  
  86. \ The program follows in Lesson 4 Part 160.
  87.