distance_from_point_to_line Function

public pure function distance_from_point_to_line(x1, x2, x) result(d)

Compute the distance between the point X and the line defined by the two points X1 and X2.

References

  1. http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html

Arguments

Type IntentOptional 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

Return Value real(kind=wp)


Calls

proc~~distance_from_point_to_line~~CallsGraph proc~distance_from_point_to_line geometry_module::distance_from_point_to_line proc~cross vector_module::cross proc~distance_from_point_to_line->proc~cross

Source Code

    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