New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deltaangle
between identical vectors return nan
#463
Comments
Guidance from ROOT: this should return zero, rather than nan. ROOT's TVector3 has an >>> import ROOT
>>> a = ROOT.TVector3(1.1, 2.2, 3.3)
>>> a.Angle(a)
0.0 I wasn't able to find a generic "angle" method on XYZVector. The issue is that in vector/src/vector/_compute/spatial/deltaangle.py Lines 34 to 37 in a9f1c74
the argument of I think a good solution would be to clamp the argument of lib.arccos(ARG) do lib.arccos(lib.maximum(-1, lib.minimum(1, ARG))) (with |
Thanks for the explanation! Just to confirm - should |
For SymPy, these functions should be the identity (no-op). Maybe we need a clearer distinction among the functions on
but because floating point numbers are not exact, (as well as functions on them, like the addition and multiplication in But SymPy has no error because it's not numerical. Passing the argument through minimum/maximum would be superfluous at best, but it's worse than that because it complicates the mathematical expression in a way that would prevent simplification. (That is, unless SymPy is smart enough to recognize that the above inequality holds, and therefore minimum/maximum with ‒1 and 1 can be dropped from the expression, but I doubt SymPy is that smart. That's asking a lot from a CAS.) It might happen at some later time that we want to use |
Thanks for the detailed explanation! I've updated the definitions for |
Vector Version
1.3.1
Python Version
3.11.4
OS / Environment
Kubuntu Linux 22.04
Describe the bug
When taking two identical vectors and computing the angle between them, I expect the result to be 0. Instead, I get NaN:
This is also true when using vector.array. I have not tried other backends.
Any additional but relevant log output
No response
The text was updated successfully, but these errors were encountered: