vector_projection Function

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

The projection of one vector onto another vector.

Reference

History

  • Jacob Williams : 7/21/2014
  • JW : fixed a typo : 6/18/2021

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_projection proc~vector_projection_on_plane vector_projection_on_plane proc~vector_projection_on_plane->proc~vector_projection proc~generate_circle stl_file%generate_circle proc~generate_circle->proc~vector_projection_on_plane proc~add_cone stl_file%add_cone proc~add_cone->proc~generate_circle proc~add_cylinder stl_file%add_cylinder proc~add_cylinder->proc~generate_circle proc~add_arrow stl_file%add_arrow proc~add_arrow->proc~add_cone proc~add_arrow->proc~add_cylinder proc~add_curve stl_file%add_curve proc~add_curve->proc~add_cylinder proc~add_axes stl_file%add_axes proc~add_axes->proc~add_arrow

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