The angle method of vectors doesn't account for approximation errors.
GoogleCodeExporter opened this issue · comments
Google Code Exporter commented
What steps will reproduce the problem?
>>> from lib.euclid import Vector2 as v
>>> vv = v(-35069.37850906927, -10011.874589043844)
>>> tt = v(-213.6847759229285, -61.004365320446894)
>>> vv.angle(tt)
Will triggere a math domain exception, because the fraction of which
to calculate the acos of will return 1.0000000000000001 instead of 1.0
It's enough to enclose the fraction in a `round()` to solve the issue.
Original issue reported on code.google.com by quasipe...@gmail.com
on 27 Sep 2011 at 9:30
Google Code Exporter commented
round() would destroy the fraction and turn all results into either 1 or 0, no?
Better use something like `min(1.0, fraction)` to cap the fraction.
Original comment by rodrigo....@gmail.com
on 6 Aug 2014 at 9:43
- Added labels: ****
- Removed labels: ****
Google Code Exporter commented
I don't think pyeuclid should set an arbitrary rounding precision: that's up
for the user. The error is better handled by clamping fractions the [-1, 1]
range prior to using trigonometric functions like acos. What do you think chris?
Original comment by rodrigo....@gmail.com
on 6 Sep 2014 at 6:56
- Added labels: ****
- Removed labels: ****
Google Code Exporter commented
You can also use round(x, n) to get n-digits of floating point precision. Using
round(x, 12) would be another way to fix this assuming you only need 12
significant digits.
Original comment by chris.fl...@gmail.com
on 6 Aug 2014 at 10:27
- Added labels: ****
- Removed labels: ****