hollowellipsoidCubeOverlap Function

private pure function hollowellipsoidCubeOverlap(me, cube) result(overlap)

This function checks intesection of solid cube and hollow ellipsoid

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

Arguments

Type IntentOptional Attributes Name
type(tem_ellipsoid_type), intent(in) :: me

ellipsoid type

type(tem_cube_type), intent(in) :: cube

cube type

Return Value logical


Called by

proc~~hollowellipsoidcubeoverlap~2~~CalledByGraph proc~hollowellipsoidcubeoverlap~2 hollowellipsoidCubeOverlap proc~tem_ellipsoidcubeoverlap~2 tem_ellipsoidCubeOverlap proc~tem_ellipsoidcubeoverlap~2->proc~hollowellipsoidcubeoverlap~2

Contents


Source Code

  pure function hollowellipsoidCubeOverlap(me, cube) result(overlap)
    ! --------------------------------------------------------------------------!
    !> ellipsoid type
    type(tem_ellipsoid_type), intent(in) :: me
    !> cube type
    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 = 1.0_rk

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

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

  end function hollowellipsoidCubeOverlap