Updates:
        Status: Accepted
        Cc: mattpap
        Labels: Geometry Polynomial

Comment #1 on issue 2120 by asmeurer: Circle(Point(0.5, 0.2),Point(1.1, 0),Point(0.5, 0.5)) raise Except
http://code.google.com/p/sympy/issues/detail?id=2120

In master I get:


In [1]: Circle(Point(0.5, 0.2),Point(1.1, 0),Point(0.5, 0.5))
---------------------------------------------------------------------------
CoercionFailed                            Traceback (most recent call last)

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/<ipython console> in <module>()

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/ellipse.py in __new__(cls, *args, **kwargs)
    358             if t.area == 0:
359 raise GeometryError("Cannot construct a circle from three collinear points")
--> 360             c = t.circumcenter
    361             r = t.circumradius
    362         elif len(args) == 2:

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/polygon.pyc in circumcenter(self)
    382         """The circumcenter of the triangle."""
    383         a,b,c = [x.perpendicular_bisector() for x in self.sides]
--> 384         return GeometryEntity.do_intersection(a, b)[0]
    385
    386     @property

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/entity.pyc in do_intersection(e1, e2)
     34
     35         try:
---> 36             return e2.intersection(e1)
     37         except NotImplementedError:
     38             n1,n2 = type(e1).__name__, type(e2).__name__

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/line.pyc in intersection(self, o)
    285             py = simplify((a2*c1 - a1*c2) / t)
    286             inter = Point(px, py)
--> 287             if (inter in self) and (inter in o):
    288                 return [inter]
    289             return []

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/line.pyc in __contains__(self, o)
    391             x = C.Symbol('x', real=True)
    392             y = C.Symbol('y', real=True)
--> 393             r = self.equation().subs({x: o[0], y: o[1]})
    394             x = simplify(r)
    395             return simplify(x) == 0

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/line.pyc in equation(self, xaxis_name, yaxis_name)
    382         y = C.Symbol(yaxis_name, real=True)
    383         a,b,c = self.coefficients
--> 384         return simplify(a*x + b*y + c)
    385
    386     def __contains__(self, o):

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/simplify/simplify.py in simplify(expr)
   1320
   1321     """
-> 1322     expr = together(cancel(powsimp(expr)).expand())
   1323     expr = powsimp(expr, combine='exp', deep=True)
   1324

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/polys/polytools.py in cancel(f, *gens, **args)
   2301             return S.One, p, q
   2302
-> 2303     c, P, Q = F.cancel(G)
   2304
   2305     if type(f) is not tuple:

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/polys/polytools.py in cancel(f, g)
   1424     def cancel(f, g):
   1425         """Cancel common factors in a rational function `f/g`.  """
-> 1426         dom, per, F, G = f.unify(g)
   1427
   1428         if F.is_zero or G.is_zero:

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/polys/polytools.py in unify(f, g)
    524                 F = DMP(dict(zip(f_monoms, f_coeffs)), dom, lev)
    525             else:
--> 526                 F = f.rep.convert(dom)
    527
    528             if g.gens != gens:

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/polys/polyclasses.py in convert(f, dom)
   1158             return f
   1159         else:
-> 1160 return DMP(dmp_convert(f.rep, f.lev, f.dom, dom), dom, f.lev)
   1161
   1162     def coeffs(f):

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/polys/densebasic.py in dmp_convert(f, u, K0, K1)
    236     v = u-1
    237
--> 238     return dmp_strip([ dmp_convert(c, v, K0, K1) for c in f ], u)
    239
    240 def dup_from_sympy(f, K):

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/polys/densebasic.py in dmp_convert(f, u, K0, K1)
    230     """Convert ground domain of `f` from `K0` to `K1`. """
    231     if not u:
--> 232         return dup_convert(f, K0, K1)
    233     if K0 is not None and K0 == K1:
    234         return f

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/polys/densebasic.py in dup_convert(f, K0, K1)
    224         return f
    225     else:
--> 226         return dup_strip([ K1.convert(c, K0) for c in f ])
    227
    228 @cythonized("u,v")

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/polys/algebratools.py in convert(K1, a, K0)
     93                     return result
     94
---> 95 raise CoercionFailed("can't convert %s of type %s to %s" % (a, K0, K1))
     96         else:
     97             try:

CoercionFailed: can't convert 0.6 of type RR to ZZ

and in polys11, I get

In [89]: Circle(Point(0.5, 0.2),Point(1.1, 0),Point(0.5, 0.5))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/<ipython console> in <module>()

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/ellipse.py in __new__(cls, *args, **kwargs)
    301             if t.area == 0:
302 raise GeometryError("Cannot construct a circle from three collinear points")
--> 303             c = t.circumcenter
    304             r = t.circumradius
    305         elif len(args) == 2:

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/polygon.pyc in circumcenter(self)
    382         """The circumcenter of the triangle."""
    383         a,b,c = [x.perpendicular_bisector() for x in self.sides]
--> 384         return GeometryEntity.do_intersection(a, b)[0]
    385
    386     @property

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/entity.pyc in do_intersection(e1, e2)
     34
     35         try:
---> 36             return e2.intersection(e1)
     37         except NotImplementedError:
     38             n1,n2 = type(e1).__name__, type(e2).__name__

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/line.pyc in intersection(self, o)
    285             py = simplify((a2*c1 - a1*c2) / t)
    286             inter = Point(px, py)
--> 287             if (inter in self) and (inter in o):
    288                 return [inter]
    289             return []

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/line.pyc in __contains__(self, o)
    391             x = C.Symbol('x', real=True)
    392             y = C.Symbol('y', real=True)
--> 393             r = self.equation().subs({x: o[0], y: o[1]})
    394             x = simplify(r)
    395             return simplify(x) == 0

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/geometry/line.pyc in equation(self, xaxis_name, yaxis_name)
    382         y = C.Symbol(yaxis_name, real=True)
    383         a,b,c = self.coefficients
--> 384         return simplify(a*x + b*y + c)
    385
    386     def __contains__(self, o):

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/simplify/simplify.py in simplify(expr)
   1112         return together(powsimp(expr))
   1113
-> 1114     expr = together(cancel(powsimp(expr)).expand())
   1115
   1116     if not isinstance(expr, Basic): # XXX: temporary hack

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/simplify/rationalsimplify.py in together(expr, deep, symbolic)
     82
     83     if not symbolic:
---> 84         return _together(sympify(expr))
     85     else:
     86         from sympy.simplify.simplify import powsimp, separate

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/simplify/rationalsimplify.py in _together(expr)
     64                 return expr
     65             elif expr.is_Add:
---> 66                 return gcd_terms(map(_together, expr.as_Add()))
     67             elif expr.is_Pow:
     68                 base = _together(expr.base)

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/core/exprtools.py in gcd_terms(terms)
    356 def gcd_terms(terms):
    357     """Compute the GCD of ``terms`` and put them together. """
--> 358     cont, numer, denom = _gcd_terms(terms)
    359     return cont*(numer/denom)
    360

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/core/exprtools.py in _gcd_terms(terms)
    328
    329     for term in terms[1:]:
--> 330         cont = cont.gcd(term)
    331
    332     for i, term in enumerate(terms):

/Users/aaronmeurer/Documents/Python/sympy/sympy-scratch/sympy/core/exprtools.py in gcd(self, other)
    282
    283     def gcd(self, other):
--> 284         return Term(self.coeff.gcd(other.coeff),
    285                     self.numer.gcd(other.numer),
    286                     self.denom.gcd(other.denom))

AttributeError: 'Real' object has no attribute 'gcd'

Of course, a workaround would be to use exact rational numbers instead of floating point ones:

In [82]: Circle(Point(S(1)/2, S(1)/5),Point(S(11)/10, 0),Point(S(1)/2, S(1)/2))
Out[82]:
⎛              ⎽⎽⎽⎽⎽⎞
⎜⎛53      ⎞  ╲╱ 610 ⎟
⎜⎜──, 7/20⎟, ───────⎟
⎝⎝60      ⎠     60  ⎠


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to