The vector v rotated by the unit quaternion q.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | q(4) |
unit quaternion [x, y, z, w], and the vector |
||
| real(kind=wp), | intent(in) | :: | v(3) |
unit quaternion [x, y, z, w], and the vector |
pure function quat_rotate(q, v) result(r) real(wp), intent(in) :: q(4), v(3) !! unit quaternion [x, y, z, w], and the vector real(wp) :: r(3) real(wp) :: t(3) ! r = v + 2 w (u x v) + 2 u x (u x v), with u = q(1:3), w = q(4) t = 2.0_wp * cross(q(1:3), v) r = v + q(4) * t + cross(q(1:3), t) end function quat_rotate