quat_rotate Function

public pure function quat_rotate(q, v) result(r)

The vector v rotated by the unit quaternion q.

Arguments

Type IntentOptional 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

Return Value real(kind=wp), (3)


Calls

proc~~quat_rotate~~CallsGraph proc~quat_rotate quat_rotate proc~cross cross proc~quat_rotate->proc~cross

Source Code

    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