# Sympy geometry: can't compute tangent lines

Here's the problem:

from sympy import symbols, Plot
from sympy.geometry import *
c1 = Circle(Point(0,0),2)
a = Point(3,0)
at = c1.tangent_lines(a)

DomainError: can't compute a Groebner basis over RR


A little web search indicates that this was a problem with older versions of sympy, but Sage includes a newer version for which this issue is not supposed to be a problem. Any ideas on how to get round this?

edit retag close merge delete

Sort by » oldest newest most voted This seems to work for me in Sage 5.6:

sage: from sympy.geometry import Circle, Point
sage: c1 = Circle(Point(0,0),2)
sage: a = Point(3,0)
sage: at = c1.tangent_lines(a)
sage: at
[Line(Point(3, 0), Point(4/3, -2*5**(1/2)/3)), Line(Point(3, 0), Point(4/3, 2*5**(1/2)/3))]


as well as on sagenb's 5.4.

BTW, star imports -- from somewhere import * -- are generally disfavoured in Python, and that's even more true in Sage, because it's very easy to accidentally rebind a name -- sin, say -- which originally referred to Sage's function with one which refers to the sin function of sympy, or mpmath, or numpy, or something, which will raise puzzling errors and be the source of mysterious bugs.

[My favourite example:

sage: all(i < 10 for i in [0..100])
False
sage: from numpy import *
sage: all(i < 10 for i in [0..100])
True


This once caused a bug in my code it took forever to track down.]

more

I discovered that my mistake (not shown in the original example) was describing circles using real numbers: Circle(Point(-0.25,0),1) instead of rationals: Circle(Point([-1/4,0]),1) And thank you for the heads-up about not importing using *. That's just me being lazy!