-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for higher dimensional rotation (#219)
* update nearest_rotation tests for 4-dimensional matrix * update indents in rotation_tests.jl * update isrotation tests * updatge RotMatrix constructor * update isrotation methods * add isrotationgenerator * add tests for isrotationgenerator * cleanup logexp.jl and add support for general dimensions * Update src/rotation_generator.jl Co-authored-by: Chris Foster <[email protected]> * update around isrotationgenerator * update tests for general dimensional rotation generator * update general dimensional log(::RotMatrix{N}) * update log(::RotMatix{N}) for Julia 1.6 * add tests for general dimensional rotation_angle * add general dimensional rotation_angle * revert general dimensional rotation_angle * add rand method for higher dimensional rotation * add tests for higher dimensional RotMatrix * add rand.jl * update multiple dispatch of Random.rand for lower dimensional RotMatrix * update comments * fix rng in rand(::RotMatrix{N}) * move rand methods to rand.jl * fix typos * add documentation for general dimensional rotations * update reference * Update docs/src/reference.md Co-authored-by: Chris Foster <[email protected]> * Update src/logexp.jl Co-authored-by: Chris Foster <[email protected]> * remove duplicated end * remove Base.log(R::Rotation{2}) etc. and update some comments * update comments suggested by @c42f Co-authored-by: Chris Foster <[email protected]>
- Loading branch information
Showing
18 changed files
with
362 additions
and
143 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# General dimensional Rotation | ||
|
||
Our main goal is to efficiently represent rotations in lower dimensions, such as 2D and 3D, but some operations on rotations in general dimensions are also supported. | ||
|
||
```@setup rotmatrixN | ||
using Rotations | ||
using StaticArrays | ||
``` | ||
|
||
**example** | ||
|
||
```@repl rotmatrixN | ||
r1 = one(RotMatrix{4}) # generate identity rotation matrix | ||
m = @SMatrix rand(4,4) | ||
r2 = nearest_rotation(m) # nearest rotation matrix from given matrix | ||
r3 = rand(RotMatrix{4}) # random rotation in SO(4) | ||
r1*r2/r3 # multiplication and division | ||
s = log(r2) # logarithm of RotMatrix is a RotMatrixGenerator | ||
exp(s) # exponential of RotMatrixGenerator is a RotMatrix | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
# Reference for rotations | ||
|
||
* [Quaternion (Wikipedia)](https://en.wikipedia.org/wiki/Quaternion) | ||
* [Quaternions and 3d rotation, explained interactively (by 3Blue1Brown)](https://www.youtube.com/watch?v=zjMuIxRvygQ) | ||
## Published articles | ||
* ["Fundamentals of Spacecraft Attitude Determination and Control" by Markley and Crassidis](https://link.springer.com/book/10.1007/978-1-4939-0802-8) | ||
* See sections 2.1-2.9 for 3d rotation parametrization. | ||
* See sections 3.1-3.2 for kinematics. | ||
* ["Derivation of the Euler-Rodrigues formula for three-dimensional rotations from the general formula for four-dimensional rotations" by Johan Ernest Mebius](https://arxiv.org/abs/math/0701759) | ||
* The conversion `RotMatrix{3}` to `QuatRotaiton` is based on this paper. | ||
* ["Computing Exponentials of Skew Symmetric Matrices And Logarithms of Orthogonal Matrices" by Jean Gallier and Dianna Xu](https://cs.brynmawr.edu/~dxu/206-2550-2.pdf) | ||
* See this article for log and exp of rotation matrices in higher dimensions. | ||
|
||
## Wikipedia articles | ||
* [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix) | ||
* [Quaternion](https://en.wikipedia.org/wiki/Quaternion) | ||
* [Wahba's problem](https://en.wikipedia.org/wiki/Wahba%27s_problem) | ||
* Wahba's problem is related to the `nearest_rotation` function. | ||
* [Polar decomposition](https://en.wikipedia.org/wiki/Polar_decomposition) | ||
* Polar decomposition is also related to the `nearest_rotation` function. | ||
|
||
## Others | ||
* ["Quaternions and 3d rotation, explained interactively" by 3Blue1Brown](https://www.youtube.com/watch?v=zjMuIxRvygQ) | ||
* ["Visualizing quaternions (4d numbers) with stereographic projection" by 3Blue1Brown](https://www.youtube.com/watch?v=d4EgbgTm0Bg) |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,42 @@ | ||
## log | ||
# 3d | ||
function Base.log(R::RotationVec) | ||
x, y, z = params(R) | ||
return RotationVecGenerator(x,y,z) | ||
end | ||
|
||
function Base.log(R::Rotation{3}) | ||
log(RotationVec(R)) | ||
end | ||
|
||
|
||
# 2d | ||
function Base.log(R::Angle2d) | ||
θ, = params(R) | ||
return Angle2dGenerator(θ) | ||
end | ||
|
||
function Base.log(R::Rotation{2}) | ||
log(Angle2d(R)) | ||
end | ||
|
||
Base.log(R::Angle2d) = Angle2dGenerator(R.theta) | ||
Base.log(R::RotMatrix{2}) = RotMatrixGenerator(log(Angle2d(R))) | ||
#= We can define log for Rotation{2} like this, | ||
but the subtypes of Rotation{2} are only Angle2d and RotMatrix{2}, | ||
so we don't need this defnition. =# | ||
# Base.log(R::Rotation{2}) = log(Angle2d(R)) | ||
|
||
## exp | ||
# 3d | ||
function Base.exp(R::RotationVecGenerator) | ||
return RotationVec(R.x,R.y,R.z) | ||
end | ||
|
||
function Base.exp(R::RotationGenerator{3}) | ||
exp(RotationVecGenerator(R)) | ||
end | ||
|
||
function Base.exp(R::RotMatrixGenerator{3}) | ||
RotMatrix(exp(RotationVecGenerator(R))) | ||
Base.log(R::RotationVec) = RotationVecGenerator(R.sx,R.sy,R.sz) | ||
Base.log(R::RotMatrix{3}) = RotMatrixGenerator(log(RotationVec(R))) | ||
Base.log(R::Rotation{3}) = log(RotationVec(R)) | ||
|
||
# General dimensions | ||
function Base.log(R::RotMatrix{N}) where N | ||
# This will be faster when log(::SMatrix) is implemented in StaticArrays.jl | ||
@static if VERSION < v"1.7" | ||
# This if block is related to this PR. | ||
# https://github.com/JuliaLang/julia/pull/40573 | ||
S = SMatrix{N,N}(real(log(Matrix(R)))) | ||
else | ||
S = SMatrix{N,N}(log(Matrix(R))) | ||
end | ||
RotMatrixGenerator((S-S')/2) | ||
end | ||
|
||
## exp | ||
# 2d | ||
function Base.exp(R::Angle2dGenerator) | ||
return Angle2d(R.v) | ||
end | ||
Base.exp(R::Angle2dGenerator) = Angle2d(R.v) | ||
Base.exp(R::RotMatrixGenerator{2}) = RotMatrix(exp(Angle2dGenerator(R))) | ||
# Same as log(R::Rotation{2}), this definition is not necessary until someone add a new subtype of RotationGenerator{2}. | ||
# Base.exp(R::RotationGenerator{2}) = exp(Angle2dGenerator(R)) | ||
|
||
function Base.exp(R::RotationGenerator{2}) | ||
exp(Angle2dGenerator(R)) | ||
end | ||
# 3d | ||
Base.exp(R::RotationVecGenerator) = RotationVec(R.x,R.y,R.z) | ||
Base.exp(R::RotMatrixGenerator{3}) = RotMatrix(exp(RotationVecGenerator(R))) | ||
# Same as log(R::Rotation{2}), this definition is not necessary until someone add a new subtype of RotationGenerator{3}. | ||
# Base.exp(R::RotationGenerator{3}) = exp(RotationVecGenerator(R)) | ||
|
||
function Base.exp(R::RotMatrixGenerator{2}) | ||
RotMatrix(exp(Angle2dGenerator(R))) | ||
end | ||
# General dimensions | ||
Base.exp(R::RotMatrixGenerator{N}) where N = RotMatrix(exp(SMatrix(R))) |
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
Oops, something went wrong.