Skip to content
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

euclid3 crashes with "math domain error" #22

Open
StarsoftAnalysis opened this issue Jan 20, 2019 · 2 comments
Open

euclid3 crashes with "math domain error" #22

StarsoftAnalysis opened this issue Jan 20, 2019 · 2 comments

Comments

@StarsoftAnalysis
Copy link

I've stumbled upon a bug in the otherwise-wonderful Python euclid library. It initially occurred with the Arch Linux package python-euclid3, and I've just reproduced it with the latest Git-cloned version from here.

Here's the problem reduced to a few lines in the interpreter. I'm not sure if there's anything special about the values 114,96 etc. -- when I tried it with simpler lines in the same directions, the problem went away.

>>> from pyeuclid.euclid import *
>>> seg = LineSegment2(Point2(114,96), Point2(117,93))
>>> vec = Vector2(0.71, -0.71)
>>> vec.angle(seg.v)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chris/projects/vplotter/hpgl_to_vplot/pyeuclid/euclid.py", line 306, in angle
    return math.acos(self.dot(other) / (self.magnitude()*other.magnitude()))
ValueError: math domain error
>>>
>>> seg = LineSegment2(Point2(0,0), Point2(3,-3))
>>> vec = Vector2(1,-1)
>>> vec.angle(seg.v)
0.0

I'm using Python 3.7.2 on up-to-date 64-bit Arch Linux.

@StarsoftAnalysis StarsoftAnalysis changed the title euclid3 crashes with math.Domain Error euclid3 crashes with "math domain error" Jan 20, 2019
@bootchk
Copy link

bootchk commented Jan 21, 2019

My initial thoughts, I could be mistaken....

"math domain error" must be from math.acos(), which requires its argument to be in a certain range -1, 1 ? (Read about atan2() and atan(), one is more lenient. Maybe pyeuclid is using too restrictive a function acos().)

Does a line segment define one vector? In other words, are you accessing a private attribute "v" of the line segment "seg" when you use "seg.v". I started by looking at the readme for pyeuclid, and it doesn't describe a method of accessing the vector of a segment. It seems to me that a line segment does NOT uniquely describe a vector.

@StarsoftAnalysis
Copy link
Author

Yes, it's an arccos vs. floating point thing: it's trying to evaluate math.acos(1.00000002).
I've fixed it by using math.atan2() instead, and could do a patch or pull request if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants