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.


Reply via email to