Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new way to represent a rotation matrix (vector rotation) #235

Closed
zhy91 opened this issue Jul 11, 2022 · 4 comments
Closed

Add new way to represent a rotation matrix (vector rotation) #235

zhy91 opened this issue Jul 11, 2022 · 4 comments

Comments

@zhy91
Copy link

zhy91 commented Jul 11, 2022

Introduction

Now, Rotations.jl contains two ways to represent rotation matrices: Euler Angles and Rotating around an axis.

However, vector rotation, i.e., rotating from one vector to another, is sometimes needed. Is it possible to add this way?

Mathematical method

References:

  1. https://www.theochem.ru.nl/~pwormer/Knowino/knowino.org/wiki/Rotation_matrix.html#Vector_rotation
  2. https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d/476311#476311

By the way, such rotation has infinite solutions. The above method gives only one of them.

Simple example

This is a simple example written by myself:

function vector_rotate(f::T, t::T) where T<:AbstractVector{Float64}
    v = f × t
    c = f  t
    u = [   0 -v[3]  v[2];
         v[3]     0 -v[1];
        -v[2]  v[1]     0]
    E = Matrix{Float64}(I, 3, 3)
    R = (c  -1.0) ? (-E) : (E + u + u * u / (1 + c))
    return R
end

Thank you all!

@zhy91
Copy link
Author

zhy91 commented Jul 11, 2022

Sorry for my stupid issue. :<

I soon realize that u and c in the above example are actually the axis and angle in the way "Rotating around an axis".
Therefore, the new way is not necessary.

@zhy91 zhy91 closed this as completed Jul 11, 2022
@tamasgal
Copy link

Sorry for digging this out but I just wanted to create a similar issue and now scratching my head how you solved it.

I guess that we can use RotationVecGenerator with f × t as an axis, something like: R = RotationVecGenerator((a × b)...) but how do we pass the angle?

@hyrodium
Copy link
Collaborator

If you need to create a rotation from an angle a and its axis [v1, v2, v3], you can use AngleAxis(a, v1, v2, v3).
If you need to create a rotation that rotates a vector u to a vector v, you can use rotation_between(u,v).

@tamasgal
Copy link

Ah yes, makes sense, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants