Skip to content

Instantly share code, notes, and snippets.

@guziy
Created October 19, 2022 14:54
Show Gist options
  • Save guziy/78d806f1eec218e9009a0aa447359acb to your computer and use it in GitHub Desktop.
Save guziy/78d806f1eec218e9009a0aa447359acb to your computer and use it in GitHub Desktop.
FUNCTION inpoly_complex2(x,y,n,xx,yy)
!-------------------------------------------------------------------------------
! Determines if a point xx,yy is inside a complex polygon
! defined by x(n),y(n),
! ref : https://wrfranklin.org/Research/Short_Notes/pnpoly.html
!
!-------------------------------------------------------------------------------
implicit none
! arguments
integer n
real*8 x(n), y(n) , xx, yy
logical inpoly_complex2
integer i, j
inpoly_complex2 = .false.
j = n
do i = 1, n
if ( ((y(i) > yy) /= (y(j) > yy)) .and. &
(xx < (x(j) - x(i)) * (yy - y(i)) / (y(j) - y(i)) + x(i)) ) then
inpoly_complex2 = .not. inpoly_complex2
endif
j = i
enddo
END FUNCTION inpoly_complex2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment