pyeuclid
pyeuclid copied to clipboard
connecting segment doesn't always intersect what it connects with
This is python code snippet that shows the problem:
intersection = segment.connect(pointLCS).intersect(segment)
Sometimes it returns None, which seems suspect.
In plain language, given any point and any first segment, a second segment that connects the point to the first segment should intersect the first segment.
I haven't really analyzed it yet. It could be that it fails when the point is colinear with the first segment. Or it could be a faulty set interpretation of segments: the end points of segments are not in the segment, i.e. the set of points in a segment is an open set. Or when the connecting segment has magnitude 0 i.e. a point, that causes problems? Or it may be when the first segment is vertical? Or maybe my understanding of geometry is incorrect: a connecting segment does not intersect?
I have been reading "Computational Geometry In C" by O'Rourke. He discusses the extreme difficulty of getting intersect() correct when using point slope algorithms, which pyeuclid does. There are many edge cases (such as vertical lines.) So I am considering the alternative which he proposes, using "signed area between three points."
This shows the test cases for pyeuclid are insufficient. But I can't find a complete set of test cases (axioms, postulates?) for geometry on the net. Seems like that would be useful.
I already have branched, just not made it public. The OO design of pyeuclid is strange, and one giant source code file is hard to read. The emphasis seems to be on performance, at the cost of correctness. I just need the geometrical objects, and use transformations from elsewhere (Qt.)
One way to fix this is to implement nearestPoint(point, other). It returns the appropriate end point of the connecting segment (the end point that intersects other.) Similarly as distance() is based on connect().
It raises the issue: what is the nearest point on a circle to the center point of the circle? Another edge test case that pyeuclid doesn't address?
Also, more guessing: the problem: "segment.connect(pointLCS).intersect(segment) returns None" might only show up for vertical lines? Or it could be a floating point issue?