This routine checks for plane box overlap this routine is conversion of c-code tribox3.c planeBoxOverlap function
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rk), | intent(in) | :: | normal(3) |
normal direction of the plane |
||
real(kind=rk), | intent(in) | :: | origin(3) |
origin of the plane |
||
real(kind=rk), | intent(in) | :: | boxhalfwidth(3) |
halfwidth of the box |
function planeBoxOverlap( normal, origin, boxhalfwidth ) result(overlaps)
!--------------------------------------------------------------------------!
!> normal direction of the plane
real(kind=rk), intent(in) :: normal(3)
!> origin of the plane
real(kind=rk), intent(in) :: origin(3)
!> halfwidth of the box
real(kind=rk), intent(in) :: boxhalfwidth(3)
logical :: overlaps
!--------------------------------------------------------------------------!
integer :: iDir
real(kind=rk) :: vmin(3), vmax(3), tmp
!--------------------------------------------------------------------------!
overlaps = .false.
! find min and max of x,y,z of distance between boxhalfwidth and origin
! depends on the direction of the plane normal
do iDir=1,3
tmp = origin(iDir)
if(normal(iDir) > 0.0_rk) then
vmin(iDir) = - boxhalfwidth(iDir) - tmp
vmax(iDir) = boxhalfwidth(iDir) - tmp
else
vmin(iDir) = boxhalfwidth(iDir) - tmp
vmax(iDir) = - boxhalfwidth(iDir) - tmp
endif
end do
if(dot_product(normal, vmin) > 0.0_rk) return
if(dot_product(normal, vmax) >= 0.0_rk) overlaps = .true.
end function planeBoxOverlap