tem_intersec_line_plane Subroutine

public subroutine tem_intersec_line_plane(plane, line, intersects, intersection)

This subroutine calculates the intersection between a plane and a line. It gives back the coordinates of the intersection, the multiple of the direction vector of the intersection and the distance of the intersection to the center point of the plan.

Arguments

Type IntentOptional Attributes Name
type(tem_plane), intent(in) :: plane
type(tem_line), intent(in) :: line
logical, intent(out) :: intersects
type(tem_intersec), intent(out) :: intersection

Called by

proc~~tem_intersec_line_plane~~CalledByGraph proc~tem_intersec_line_plane tem_intersec_line_plane proc~exit_element exit_element proc~exit_element->proc~tem_intersec_line_plane

Source Code

  subroutine tem_intersec_line_plane( plane, line, intersects, intersection )
    ! ---------------------------------------------------------------------------
    type(tem_plane), intent(in) :: plane
    type(tem_line), intent(in) :: line
    type(tem_intersec), intent(out) :: intersection
    logical, intent(out) :: intersects
    ! ---------------------------------------------------------------------------
    real(kind=rk) :: alignment, dist
    ! ---------------------------------------------------------------------------

    alignment = dot_product(plane%normal, line%direction)
    dist = dot_product( plane%normal, ( plane%coord - line%coordStart ))
    intersects = (alignment > epsilon(alignment))

    if (intersects) then
      intersection%lambda = dist / alignment
      intersection%coord = line%coordStart + intersection%lambda               &
        &                * line%direction
    else
      if (dist < 16*tiny(dist)) then
        ! Line is parallel to the plane, but on the plane
        intersects = .true.
        intersection%lambda = 0.0_rk
      else
        ! Line is parallel to the plane, no intersection!
        intersection%lambda = huge(intersection%lambda)
      end if
      intersection%coord = line%coordStart
    end if
    intersection%distance = plane%coord - intersection%coord

  end subroutine tem_intersec_line_plane