polyarea(3f) - [M_math:geometry] compute the area bounded by a simple closed polygonal curve
Synopsis
Description
Options
Returns
Example
FUNCTION polyarea(x, y) RESULT(fn_val)
REAL, INTENT(IN) :: x(:) REAL, INTENT(IN) :: y(:) REAL :: fn_val
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.
The X and Y arrays are assumed to be of the same size.
x x coordinates of the points that define the simple polygon y y coordinates of the points that define the simple polygon
fn_val the area of the simple polygon
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
| |||||||||||||
Nemo Release 3.1 | polyarea (3) | February 23, 2025 |