vector_projection Function

public pure function vector_projection(a, b) result(c)

The projection of one vector onto another vector.

Reference

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: a

the original vector

real(kind=wp), intent(in), dimension(size(a)) :: b

the vector to project on to

Return Value real(kind=wp), dimension(size(a))

the projection of a onto b


Called by

proc~~vector_projection~~CalledByGraph proc~vector_projection vector_module::vector_projection proc~vector_projection_on_plane vector_module::vector_projection_on_plane proc~vector_projection_on_plane->proc~vector_projection

Source Code

    pure function vector_projection(a,b) result(c)

    implicit none

    real(wp),dimension(:),intent(in)       :: a  !! the original vector
    real(wp),dimension(size(a)),intent(in) :: b  !! the vector to project on to
    real(wp),dimension(size(a))            :: c  !! the projection of a onto b

    real(wp) :: bmag2

    bmag2 = dot_product(b,b)

    if (bmag2==zero) then
        c = zero
    else
        c = b * dot_product(a,b) / bmag2
    end if

    end function vector_projection