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

Construct rotation that aligns two vectors #244

Closed
Kolaru opened this issue Nov 15, 2022 · 2 comments
Closed

Construct rotation that aligns two vectors #244

Kolaru opened this issue Nov 15, 2022 · 2 comments

Comments

@Kolaru
Copy link

Kolaru commented Nov 15, 2022

Sometimes it is nice to have the rotation that aligns two vectors (e.g. when aligning randomly oriented data according to a chosen frame).

If it is a good fit for the package, I can try to make a PR. I already have some code doing it laying somewhere.

@hyrodium
Copy link
Collaborator

This function seems already implemented as Rotations.rotation_between.

julia> using Rotations, LinearAlgebra

julia> r = Rotations.rotation_between([1,0,0],[0,1/√2,1/√2])
3×3 QuatRotation{Float64} with indices SOneTo(3)×SOneTo(3)(QuaternionF64(0.707107, 0.0, -0.5, 0.5, false)):
 -1.11022e-16  -0.707107  -0.707107
  0.707107      0.5       -0.5
  0.707107     -0.5        0.5

julia> r * [1,0,0]
3-element StaticArraysCore.SVector{3, Float64} with indices SOneTo(3):
 -1.1102230246251565e-16
  0.7071067811865475
  0.7071067811865475

julia> dot(rotation_axis(r), [1,0,0])
3.437762736252422e-63

julia> dot(rotation_axis(r), [0,1/√2,1/√2])
0.0

@hyrodium
Copy link
Collaborator

hyrodium commented Jan 7, 2023

Please comment here if Rotations.rotation_between is not sufficient.

@hyrodium hyrodium closed this as completed Jan 7, 2023
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

2 participants