[UP]


Manual Reference Pages  - polyarea (3)

NAME

polyarea(3f) - [M_math:geometry] compute the area bounded by a simple closed polygonal curve

CONTENTS

Synopsis
Description
Options
Returns
Example

SYNOPSIS

FUNCTION polyarea(x, y) RESULT(fn_val)

      REAL, INTENT(IN)     :: x(:)
      REAL, INTENT(IN)     :: y(:)
      REAL                 :: fn_val

DESCRIPTION

Given a sequence of points (X(I),Y(I)), polyarea(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
y y coordinates of the points that define the simple polygon
The X and Y arrays are assumed to be of the same size.

RETURNS

fn_val the area of the simple polygon

EXAMPLE

Sample program:

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

program demo_polyarea use M_math, only : polyarea 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=’,polyarea(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=’,polyarea(x,y)

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

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

end program demo_polyarea

polyarea=
  0.00000000
polyarea=
  -100.000000
polyarea=
  -100.000000
polyarea=
  -100.000000


polyarea (3) October 17, 2020
Generated by manServer 1.08 from 76c5b847-f6eb-4a55-a7b4-091af27aa2e8 using man macros.