hollowSphereCubeOverlap Function

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

This function checks intesection of solid cube and hollow 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~~hollowspherecubeoverlap~~CalledByGraph proc~hollowspherecubeoverlap hollowSphereCubeOverlap proc~tem_spherecubeoverlap tem_sphereCubeOverlap proc~tem_spherecubeoverlap->proc~hollowspherecubeoverlap proc~tem_cylindercubeoverlap tem_cylinderCubeOverlap proc~tem_cylindercubeoverlap->proc~tem_spherecubeoverlap proc~tem_shape_subtreefromgeominters tem_shape_subTreeFromGeomInters proc~tem_shape_subtreefromgeominters->proc~tem_spherecubeoverlap proc~tem_shape_subtreefromgeominters->proc~tem_cylindercubeoverlap proc~tem_shape2subtree tem_shape2subTree proc~tem_shape2subtree->proc~tem_shape_subtreefromgeominters proc~tem_create_subtree_of tem_create_subTree_of proc~tem_create_subtree_of->proc~tem_shape2subtree

Source Code

  function hollowSphereCubeOverlap(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,a, b
    integer :: i
    real(kind=rk) :: dmin, dmax
    ! -------------------------------------------------------------------------!
    !minimum distance
    dmin = 0.0_rk
    !maximum distance
    dmax = 0.0_rk

    rsqr = sphere%radius**2

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

    overlap = ( (dmin <= rsqr) .and. (dmax >= rsqr) )

  end function hollowSphereCubeOverlap