dfki-ric / pytransform3d

3D transformations for Python.
https://dfki-ric.github.io/pytransform3d/
Other
618 stars 65 forks source link

Fix incorrect coordinate transforms with integer inputs #230

Closed danielpmorton closed 1 year ago

danielpmorton commented 1 year ago

Certain functions in the Coordinates package result in incorrect transformations when the inputs are integer arrays, rather than float arrays. Below are a few examples of some invalid results that can be fixed with a conversion

This issue seems to be limited to the functions in the Coordinates package that used np.arctan2, but you may want to consider checking some of your other functions too. I did not seem to notice the issue with the other functions in Coordinates.

In [27]: ptc.spherical_from_cylindrical([1., 0, 0])
Out[27]: array([1.        , 1.57079633, 0.        ])

In [28]: ptc.spherical_from_cylindrical([1, 0, 0])
Out[28]: array([1, 1, 0])
In [29]: ptc.spherical_from_cartesian([1, 0, 0])
Out[29]: array([1, 1, 0])

In [30]: ptc.spherical_from_cartesian([1., 0, 0])
Out[30]: array([1.        , 1.57079633, 0.        ])
In [44]: ptc.cylindrical_from_cartesian([0, 1, 0])
Out[44]: array([1, 1, 0])

In [45]: ptc.cylindrical_from_cartesian([0, 1., 0])
Out[45]: array([1.        , 1.57079633, 0.        ])
AlexanderFabisch commented 1 year ago

Hi @danielpmorton ,

thanks for your contribution. It would be great if you could also add unit tests that check these cases here.

I also changed the pull request to the branch develop-3, which will be merged to master as soon as I release version 3.0.0.

danielpmorton commented 1 year ago

Done! Added the test cases. The first three are really the only ones that were giving an issue, but I added similar tests and made the same changes to the other functions in Coordinates for consistency. I also rebased the branch on develop-3

AlexanderFabisch commented 1 year ago

Thanks a lot!