The projection of one vector onto another vector.
Type | Intent | Optional | 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 |
the projection of a onto b
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