[UP]


Manual Reference Pages  - polyarea_shoelace (3)

NAME

polyarea_shoelace(3f) - [M_math:geometry] compute area bounded by a simple closed polygon using the shoelace algorithm

CONTENTS

Synopsis
Description
Options
Returns
Example

SYNOPSIS

function polyarea_shoelace(x, y)

   class(*), intent(in) :: x(:)
   class(*), intent(in) :: y(:)
   doubleprecision      :: polyarea_shoelace

DESCRIPTION

Given a sequence of points (X(I),Y(I)), polyarea_shoelace(3f) computes the area bounded by the closed polygonal curve which passes through the points in the order that they are indexed. The final point of the curve is assumed to be the first point given. Therefore, it need not be listed at the end of X and Y. The polygon should be simple (e.g. It may not cross over itself).

If the vertices are given in counterclockwise order, the area will be positive. If the vertices are given in clockwise order, the area will be negative.

OPTIONS

x x coordinates of the points that define the simple polygon. May be any standard scalar numeric value type supported by M_anything::anyscalar_to_double(3f).
y y coordinates of the points that define the simple polygon. May be any standard scalar numeric value type supported by M_anything::anyscalar_to_double(3f).
The X and Y arrays are assumed to be of the same size.

RETURNS

polyarea_shoelace
  the area of the simple polygon

EXAMPLE

Sample program:

   !   (0,10) ########### (10,10)
   !          ##       #
   !          # #     #
   !          #  #   #
   !          #   # #
   !          #    #
   !          #   # #
   !          #  #   #
   !          # #     #
   !          ##       #
   !     (0,0)########### (10,0)

program demo_polyarea_shoelace use M_math, only : polyarea_shoelace implicit none ! A B C D E F real,allocatable :: x(:) real,allocatable :: y(:)

x=[ 0.0, 10.0, 0.0, 10.0, 0.0, 0.0] !! hourglass crosses itself. unexpected value y=[10.0, 10.0, 0.0, 0.0, 10.0, 10.0] write(*,*)’polyarea_shoelace=’,polyarea_shoelace(x,y)

x=[ 0.0, 10.0, 0.0, 0.0, 10.0, 0.0, 0.0] !! crosses itself. maybe not what you expect y=[10.0, 10.0, 0.0, 10.0, 0.0, 0.0, 10.0] write(*,*)’polyarea_shoelace=’,polyarea_shoelace(x,y)

x=[ 0.0, 0.0, 10.0, 10.0, 0.0 ] ! square clockwise

y=[ 0.0, 10.0, 10.0, 0.0, 0.0 ] write(*,*)’polyarea_shoelace=’,polyarea_shoelace(x,y)

x=[ 0.0, 0.0, 10.0, 10.0, 0.0 ] ! square counterclockwise y=[10.0, 0.0, 0.0, 10.0, 10.0 ] write(*,*)’polyarea_shoelace=’,polyarea_shoelace(x,y)

end program demo_polyarea_shoelace

Results:

    polyarea_shoelace=   0.0000000000000000
    polyarea_shoelace=  -100.00000000000000
    polyarea_shoelace=  -100.00000000000000
    polyarea_shoelace=   100.00000000000000


polyarea_shoelace (3) October 17, 2020
Generated by manServer 1.08 from f7322eff-54ba-4f7a-949a-569d10f4c33b using man macros.