Rotate a 3x1 vector in space, given an axis and angle of rotation.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(3) | :: | v |
vector to rotate |
|
real(kind=wp), | intent(in), | dimension(3) | :: | k |
rotation axis |
|
real(kind=wp), | intent(in) | :: | theta |
rotation angle [rad] |
||
real(kind=wp), | intent(out), | dimension(3) | :: | vrot |
result |
pure subroutine axis_angle_rotation(v,k,theta,vrot) implicit none real(wp),dimension(3),intent(in) :: v !! vector to rotate real(wp),dimension(3),intent(in) :: k !! rotation axis real(wp),intent(in) :: theta !! rotation angle [rad] real(wp),dimension(3),intent(out) :: vrot !! result real(wp),dimension(3) :: khat real(wp) :: ct,st ct = cos(theta) st = sin(theta) khat = unit(k) !rotation axis unit vector vrot = v*ct + cross(khat,v)*st + khat*dot_product(khat,v)*(one-ct) end subroutine axis_angle_rotation