Results 1 to 4 of 4

Thread: VB Snippet - Math - Algorithm for the area of any polygon

Threaded View

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    VB Snippet - Math - Algorithm for the area of any polygon

    VB Code:
    1. Public Function Area(xpoly, ypoly, npoly)
    2.  
    3. '***********************************************************************
    4. 'Calculates the area of a closed contour (polygon) of any shape
    5. 'defined by xpoly(i),ypoly(i) with i=1,2,...,npoly
    6. 'The last point must close the contour, i.e.
    7. 'xpoly(1)=xpoly(npoly) & ypoly(1)=ypoly(npoly)
    8. 'Minimum npoly is 4 (i.e. a triangle)
    9. '***********************************************************************
    10.     Dim a As Single
    11.    
    12.     'Check for minimum num. of pts.
    13.     If npoly < 4 Then
    14.         Area = 0
    15.         Exit Function
    16.     End If
    17.    
    18.     a = 0   'Initialize area
    19.     For i = 1 To npoly - 1
    20.         a = a + xpoly(i) * (ypoly(i + 1) - ypoly(i)) - ypoly(i) * (xpoly(i + 1) - xpoly(i))
    21.     Next
    22.    
    23.     Area = 0.5 * a
    24. End Function
    Last edited by krtxmrtz; May 7th, 2003 at 08:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width