Calculates normalized vectors that are perpendicular to b
such that a
x c
= b_norm
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=Float64), | intent(in), | dimension(3) | :: | b | ||
real(kind=Float64), | intent(out), | dimension(3) | :: | a | ||
real(kind=Float64), | intent(out), | dimension(3) | :: | c |
subroutine calc_perp_vectors(b, a, c)
!+ Calculates normalized vectors that are perpendicular to b
!+ such that `a` x `c` = `b_norm`
real(Float64), dimension(3), intent(in) :: b
real(Float64), dimension(3), intent(out) :: a
real(Float64), dimension(3), intent(out) :: c
real(Float64), dimension(3) :: bnorm
bnorm=b/norm2(b)
if (abs(bnorm(3)).eq.1) then
a=[1.d0,0.d0,0.d0]
c=[0.d0,1.d0,0.d0]
else
if (bnorm(3).eq.0.) then
a=[0.d0,0.d0,1.d0]
c=[bnorm(2),-bnorm(1), 0.d0]/sqrt(bnorm(1)**2+bnorm(2)**2)
else
a=[bnorm(2),-bnorm(1),0.d0]/sqrt(bnorm(1)**2+bnorm(2)**2)
c=-[ a(2) , -a(1) , (a(1)*bnorm(2)-a(2)*bnorm(1))/bnorm(3) ]
c=c/norm2(c)
if(bnorm(3).lt.0.0) then
c=-c
endif
endif
endif
end subroutine calc_perp_vectors