ajhynes7/scikit-spatial

`angle_signed` for 3D Vectors

CristianoPizzamiglio opened this issue · 2 comments

Hi @ajhynes7!

The angle_between method allows to compute the unsigned angle between two either 2D or 3D vectors, while the angle_signed computes the signed angle but supports 2D vectors only.

I had a use case where I needed to compute the signed angle between two 3D vectors. Would you be interested in changing the angle_signed method to support 3D vectors as well? If you wouldn't, don't worry, I understand.

I was thinking about the following solution that does not break the current interface. Only the angle_signed method would be modified.

I would add the keyword argument positive_direction or plane_normal which is a Vector that is necessary to actually determine if the angle between two 3D vectors is positive or not. Its default value is None. This vector is just the normal of the plane where the two 3D vectors lie. We need to validate this input to actually check if it's a Vector and normal.

If the user provides two 2D vectors, the method works as it is now and the positive_direction argument is ignored regardless of its value.

If the user provides two 3D vectors and the positive_direction is not None, then the cross product of the two input vectors is computed and eventually the cosine similarity is computed between the cross product and the positive_direction vector which will be used to determine the sign of the angle.
If positive_direction is None a positive angle will be always returned.

Thanks!

Hi @CristianoPizzamiglio , do you want to try creating a PR for this?

Yes, I do, it's a pleasure!