Skip to content

Instantly share code, notes, and snippets.

@cserteGT3
Created April 4, 2019 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cserteGT3/49930f0c4f189f4539bb0966bdadff61 to your computer and use it in GitHub Desktop.
Save cserteGT3/49930f0c4f189f4539bb0966bdadff61 to your computer and use it in GitHub Desktop.
Included in generatesamples.jl
module RodriguesRotations
using LinearAlgebra
using ZChop: zchop
export rodriguesdeg, rodriguesrad
"""
rodrigues(nv, Θ)
Create a rotation matrix from a normalized axis and an angle (in radian).
Near-zero elements will be chopped to zero.
"""
function rodrigues(nv, Θ)
et = eltype(nv)
R = zeros(et,3,3)
R = nv*nv' + cos(Θ).*(Matrix{et}(I, 3,3) - nv*nv') + sin(Θ).*crossprodtensor(nv)
return R
end
"""
crossprodtensor(v)
Create the cross product tensor of 3 dimensional vector.
"""
function crossprodtensor(v)
[0 -v[3] v[2];
v[3] 0 -v[1];
-v[2] v[1] 0]
end
"""
rodriguesrad(nv, ϑ)
Create a rotation matrix from an axis (`nv`) and an angle (`ϑ`) in radians.
"""
function rodriguesrad(nv, ϑ)
nvn = normalize(nv)
return rodrigues(nvn, ϑ)
end
"""
rodriguesdeg(nv, ϑ)
Create a rotation matrix from an axis (`nv`) and an angle (`ϑ`) in degrees.
"""
function rodriguesdeg(nv, ϑ)
nvn = normalize(nv)
return rodrigues(nvn, deg2rad(ϑ))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment