So I checked, and the issue is that Point calls nsimplify on its coordinates by default. This can be undone by calling Point(evaluate=False), but this is not enough, because points are created internally as well, and evaluate defaults to True. The following patch to the geometry module will make this work as you want:
diff --git a/sympy/geometry/point.py b/sympy/geometry/point.py index 899e344..d1fdc01 100644 --- a/sympy/geometry/point.py +++ b/sympy/geometry/point.py @@ -85,7 +85,7 @@ def __new__(cls, *args, **kwargs): if len(coords) != 2: raise NotImplementedError( "Only two dimensional points currently supported") - if kwargs.get('evaluate', True): + if kwargs.get('evaluate', False): coords = [nsimplify(c) for c in coords] return GeometryEntity.__new__(cls, *coords) Try applying it and see if that makes your code go a little faster. With it, we get In [5]: e2 = Ellipse(Point(3.1, 1.1), hradius=3.1, eccentricity=0.8) In [6]: r = Ray(Point(-2.1, 3.1), Point(3.1, 1.1)) In [7]: e2.intersection(r) Out[7]: [Point(0.490174669211991, 2.10377897338), Point(5.70982533078801, 0.0962210266199968)] In [8]: r = Ray(Point(-2, 3), Point(3, 1)) In [9]: e2 = Ellipse(Point(3, 1), hradius=3, eccentricity=Rational(4, 5)) In [10]: e2.intersection(r) Out[10]: [Point(-9*sqrt(13)/13 + 3, 18*sqrt(13)/65 + 1), Point(9*sqrt(13)/13 + 3, -18*sqrt(13)/65 + 1)] Aaron Meurer On Tue, Feb 5, 2013 at 5:18 PM, Aaron Meurer <asmeu...@gmail.com> wrote: > Probably this is because the geometry module computes everything > exactly, even if you use floating point numbers. If you do, it > somewhere converts these to rationals, which can lead to very big > floating point numbers. For example: > > In [25]: r = Ray(Point(-2.1, 3.1), Point(3.1, 1.1)) > > In [26]: e2 = Ellipse(Point(3.1, 1.1), hradius=3.1, eccentricity=0.8) > > In [27]: e2.intersection(r) > Out[27]: > [Point(-260000000*sqrt(1102760755899847)/3308282267699541 + 31/10, > 100000000*sqrt(1102760755899847)/3308282267699541 + 11/10), > Point(260000000*sqrt(1102760 > 755899847)/3308282267699541 + 31/10, > -100000000*sqrt(1102760755899847)/3308282267699541 + 11/10)] > > Someone who is more familiar with the geometry module will have to > comment if this is easy to work around or not. In the meanwhile, I > opened http://code.google.com/p/sympy/issues/detail?id=3617. > > Aaron Meurer > > On Tue, Feb 5, 2013 at 12:54 PM, Ahmed Kachkach > <ahmed.kachk...@gmail.com> wrote: >> Hi ! >> >> For a robotics simulation, I need to calculate the distance that an >> ultrasound sensor would measure (=> distance to the closest obstacle). >> >> Here's the code I'm using to do so (knowing that what's in "self.shapes" has >> been parsed from an SVG file and is mainly ellipses): >> >>>> def RayDistance(self, x, y, headingAngle): >>>> >>>> ray = Ray(Point(x,y), angle=headingAngle) >>>> >>>> minDist = None >>>> >>>> for shape in self.shapes: >>>> >>>> intersections = ray.intersection(shape) >>>> >>>> for intersection in intersections: >>>> >>>> distance = intersection.distance(ray.source) >>>> >>>> print "Shape {} ; Intersection {} ; Distance {}".format(shape, >>>> intersection, distance) >>>> >>>> if minDist == None: >>>> >>>> minDist = distance >>>> >>>> elif distance < minDist: >>>> >>>> minDist = distance >>>> >>>> return minDist >> >> >> Doing this is extremely slow, even with just 3 shapes. If I go up to 200 >> shapes, I only get about 1 frame per second. And I only detectect a >> collision from time to time (especially if I slightly change my heading >> angle while facing a same obstacle). >> >> For instance, I'm using Qt for the visualisation and my "headingAngle" is in >> radians and ccw (0 being horizantal, headed to the positive x), my >> coordinates are floats and using the graphical reference system (=> positive >> Xs to the "right" and positive Ys to the bottom) >> >> It's my first experience with Sympy, so I may just be using the wrong tools >> for what I'm trying to do. >> >> Thank you in advance! >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sympy+unsubscr...@googlegroups.com. >> To post to this group, send email to sympy@googlegroups.com. >> Visit this group at http://groups.google.com/group/sympy?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.