Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds a
quat.rotate_broadcast(vecs)
method. Standard NumPy broadcasting rules are used to determine the shape of its output. This means that for an Nx4 quaternionic array and an Nx3 vector array, an Nx3 rotated vector array will be output. This is in contrast to the existing.rotate()
method which operates as an outer product and would return an NxNx3 rotated vector array.My initial use case for this is using this for coordinate transforms. If we have a series of poses stored as Nx3 positions and Nx4 quaternions, the result of rotating vectors as part of changing coordinate systems should be Nx3.
Note that I have implemented this with the standard
q * v * q.inverse
method as some benchmarking indicated this was faster than the Euler-Rodrigues formula given in the docstring of.rotate
except for small numbers of rotations. I have uploaded the benchmark script I wrote to https://gist.github.com/bcbnz/72ccebe4cc3d6e5ad3666953bfe3c6d5 and a subset of the generated images are below. The benchmark also asserts the results areallclose
with each other and with the existing.rotate()
(either fully if the output shapes are the same, or on the first quaternion & vector if not). The benchmarked functions did not include the error checking included in the pull request.The unit tests compare results against the
.rotate
method. In simple cases, these will have the same shape. In the other cases, we can compare with the diagonal vector components.I have not mentioned the new method in the docstring of
.rotate
as I wasn't sure what to do with its comments about the alternative method. I am happy to add a commit or do a force push modifying it with some guidance on the appropriate changes, or you are of course welcome to do so yourself (I have set the 'allow edits by maintainers' option in this pull request).