erwincoumans / tiny-differentiable-simulator

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.
Apache License 2.0
1.23k stars 130 forks source link

Normalize quaternion in rotate(q, v) #135

Closed ErikGartner closed 3 years ago

ErikGartner commented 3 years ago

During contact computation I have noticed that the collision geometry poses sometimes are not perfectly normalized. When we then call rotate we rotate a vector with an unnormalized quaternion. A quick fix would be to normalize here.

I haven't dug into this deeper into the root cause but it seems like it might happen when we go from rotation matrices to quaternions here: https://github.com/google-research/tiny-differentiable-simulator/blob/a564170bef387522c7149bbaa843ba0125e1a900/src/world.hpp#L247

erwincoumans commented 3 years ago

Thanks for the PR. Would it help to move the normalize into the matrix_to_quat function instead? Or are there other locations that need patching?

ErikGartner commented 3 years ago

It seems to be sufficient for my use case to only normalize in world.hpp. I made a new PR that for.

https://github.com/google-research/tiny-differentiable-simulator/pull/135