1

I noticed that my Python 2.7 code is slow because SymPy uses exact rationals instead of floats as its numbers. My code basically computes intersections between lines, planes and similar geometric objects. I found this question in which it's explained that you can speed up geometric objects creation by passing in evaluate=False, which forces SymPy to keep the floats. I've done this for the objects I'm intersecting, though the intersection result is returned using exact rationals (while I want floats, even if precision is lost). For example:

>>> import sympy as sp
>>> l = sp.Line((0,0),(1.1,1.1), evaluate=False)
>>> sp.Line((1.1,0),(0,1.1), evaluate=False).intersection(l)
[Point2D(11/20, 11/20)]

How can I disable the exact computation? An alternative library will also be considered.

squire
  • 31
  • 4

1 Answers1

0

This is not really about intersection. When you do

l = Line((0, 0), (1.1, 1.1), evaluate=False)

the result is Line2D(Point2D(0, 0), Point2D(11/10, 11/10)) - the rationals are already there. The reason is that you passed tuples instead of points, so the creator of Line class first converts them to Points. And that conversion happens with the default evaluate setting.

So, use evaluate=False earlier in the process:

l = Line(Point((0, 0), evaluate=False), Point((1.1, 1.1), evaluate=False))
res = Line(Point((1.1, 0), evaluate=False), Point((0, 1.1), evaluate=False)).intersection(l)

which returns [Point2D(0.550000000000000, 0.550000000000000)]

(This is assuming from sympy import Line, Point, as I don't like typing the prefix all the time.)

I don't promise this will make the process any faster. The Geometry module is not known for efficiency.