Created
April 4, 2019 07:16
-
-
Save cserteGT3/49930f0c4f189f4539bb0966bdadff61 to your computer and use it in GitHub Desktop.
Included in generatesamples.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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