planeBoxOverlap Function

private function planeBoxOverlap(normal, origin, boxhalfwidth) result(overlaps)

This routine checks for plane box overlap this routine is conversion of c-code tribox3.c planeBoxOverlap function

Arguments

Type IntentOptional 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

Return Value logical


Called by

proc~~planeboxoverlap~2~~CalledByGraph proc~planeboxoverlap~2 planeBoxOverlap proc~triboxoverlap_loc~2 triBoxOverlap_loc proc~triboxoverlap_loc~2->proc~planeboxoverlap~2 proc~tem_trianglecubeoverlap~2 tem_triangleCubeOverlap proc~tem_trianglecubeoverlap~2->proc~triboxoverlap_loc~2

Contents

Source Code


Source Code

  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