Compute the distance between the point X and the line defined by the two points X1 and X2.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(3) | :: | x1 | ||
real(kind=wp), | intent(in), | dimension(3) | :: | x2 | ||
real(kind=wp), | intent(in), | dimension(3) | :: | x |
pure function distance_from_point_to_line (x1, x2, x) result(d) implicit none real(wp),dimension(3),intent(in) :: x1 real(wp),dimension(3),intent(in) :: x2 real(wp),dimension(3),intent(in) :: x real(wp) :: d real(wp),dimension(3) :: x21 real(wp) :: x21_mag x21 = x2 - x1 x21_mag = norm2(x21) if (x21_mag/=0.0_wp) then d = norm2( cross( x21, x1 - x ) ) / x21_mag else d = norm2(x1 - x) end if end function distance_from_point_to_line