Distance from point v to the segment from a to b.
| Type | Intent | Optional | 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 |
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