segment_distance Function

private pure function segment_distance(v, a, b) result(d)

Distance from point v to the segment from a to b.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: v(3)

the point, and the segment's ends

real(kind=wp), intent(in) :: a(3)

the point, and the segment's ends

real(kind=wp), intent(in) :: b(3)

the point, and the segment's ends

Return Value real(kind=wp)


Called by

proc~~segment_distance~~CalledByGraph proc~segment_distance segment_distance proc~update_lod update_lod proc~update_lod->proc~segment_distance proc~written LineChain%written proc~written->proc~update_lod proc~write_intermediates write_intermediates proc~write_intermediates->proc~written proc~write_marker write_marker proc~write_marker->proc~written proc~write_segments write_segments proc~write_segments->proc~written proc~write_segments~2 write_segments proc~write_segments~2->proc~written proc~add_intermediates add_intermediates proc~add_intermediates->proc~write_intermediates proc~marker_update MarkerArtist%marker_update proc~marker_update->proc~write_marker proc~marker_update->proc~add_intermediates proc~segment_update SegmentArtist%segment_update proc~segment_update->proc~write_segments proc~segments_late_update CustomLineSegments%segments_late_update proc~segments_late_update->proc~write_segments~2

Source Code

    pure real(wp) function segment_distance(v, a, b) result(d)
        real(wp), intent(in) :: v(3), a(3), b(3) !! the point, and the segment's ends
        real(wp) :: ab(3), t, len2
        ab = b - a
        len2 = dot_product(ab, ab)
        t = 0.0_wp
        if (len2 > 0.0_wp) t = max(0.0_wp, min(1.0_wp, dot_product(v - a, ab) / len2))
        d = norm2(v - (a + t * ab))
    end function segment_distance