solidSphereCubeOverlap Function

private function solidSphereCubeOverlap(sphere, cube) result(overlap)

This function checks intesection of solid cube and solid sphere

This algorithm is taken from http://tog.acm.org/resources/GraphicsGems/gems/BoxSphere.c

Arguments

Type IntentOptional Attributes Name
type(tem_sphere_type), intent(in) :: sphere
type(tem_cube_type), intent(in) :: cube

Return Value logical


Called by

proc~~solidspherecubeoverlap~2~~CalledByGraph proc~solidspherecubeoverlap~2 solidSphereCubeOverlap proc~tem_spherecubeoverlap~2 tem_sphereCubeOverlap proc~tem_spherecubeoverlap~2->proc~solidspherecubeoverlap~2

Contents


Source Code

  function solidSphereCubeOverlap(sphere, cube) result(overlap)
    ! -------------------------------------------------------------------------!
    !inferface variables
    type(tem_sphere_type), intent(in) :: sphere !< spacer geometry data
    type(tem_cube_type), intent(in) :: cube
    logical :: overlap !< return value
    ! -------------------------------------------------------------------------!
    ! local variables
    real(kind=rk) :: rsqr
    integer :: i
    real(kind=rk) :: dmin
    ! -------------------------------------------------------------------------!
    !minimum distance
    dmin = 0.0_rk

    rsqr = sphere%radius**2

    do i=1,3
      if ( sphere%origin(i) < cube%origin(i) ) then
        dmin = dmin + ( sphere%origin(i) - cube%origin(i) )**2
      else if ( sphere%origin(i) > cube%endPnt(i) ) then
        dmin = dmin +  ( sphere%origin(i) - cube%endPnt(i) )**2
      end if
    end do

    overlap = (dmin <= rsqr)

  end function solidSphereCubeOverlap