wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
624 stars 105 forks source link

rotation is mathematically wrong #166

Closed philippeseil closed 3 years ago

philippeseil commented 3 years ago

The application of the rotation matrix (here https://github.com/WoLpH/numpy-stl/blob/develop/stl/base.py#L511 and here https://github.com/WoLpH/numpy-stl/blob/develop/stl/base.py#L514 ) is mathematically wrong, it produces clockwise rotation for positive angles. The code linked above computes row vector times matrix. Since

(M x v)^T = v^T x M^T

, rotation matrices are antisymmetric, and the multiplication with the transposed/inverse is equivalent to rotating in the opposite direction, the issue occurs. This can be easily fixed by transposing the rotation matrix before the dot() call.

You might be reluctant to change the behavior of the function in such a drastic way, which is understandable. If you decide not to fix this, please at least note it in the documentation. Thanks.

wolph commented 3 years ago

I have honestly never looked at the mathematics for the rotation code in detail, but I believe you are indeed right. And you are also right that this is major behaviour to change so I'm somewhat hesitant about that.

I'm definitely going to add it as a comment and I might also add a flag to transpose before the dot.