Repository: sympy/sympy

Issue:
Invalid results by `is_tangent`
What's Wrong:
```python
>>> from sympy import *
>>> c = Circle(Point(0,0),2)
>>> poly1 = Polygon((-2,-2),(-2,2),(2,2),(3,0),(2,-2))
>>> c.is_tangent(poly1)
True
>>> poly2 = Polygon((2,2),(3,0),(2,-2),(-2,-2),(-2,2))
>>> c.is_tangent(poly2)
False
>>> r = Ray(Point(0,2),Point(2,2))
>>> c.is_tangent(r)
False
```

notice that poly1 and poly2 are giving different results,
but are same polygon except there starting points are different.
Further, in my opinion( I found very less on this topic on internet but by definition in google),  tangent is a straight line or plane that touches a curve or curved surface at a point, but if EXTENDED does not cross it at that point.
the ray,r touches the circle,c at r.source but when extended does not cross circle,c at any point. by this definition r is a tangent to circle c.

Changes I made:
change 1-
Line Number:720-730
       if one or more sides of polygon are tangent to ellipse and other does not touch it, polygon is a tangent
      

change 2-
Line Number: 714
       original content : 
                return intersect[0] != o.source and not self.encloses_point(o.source)
       my change:
                return o in self.tangent_lines(intersect[0])[0]

Orignally reported at https://github.com/sympy/sympy/pull/13496 by @Amit-Modi

Discussion:

Patch:
diff --git a/sympy/geometry/ellipse.py b/sympy/geometry/ellipse.py
index e191ee6942..f096556f4b 100644
--- a/sympy/geometry/ellipse.py
+++ b/sympy/geometry/ellipse.py
@@ -767,7 +767,7 @@ def is_tangent(self, o):
                     else:
                         return False
                 else:
-                    return all_tangents
+                    return False
             return all_tangents
         elif isinstance(o, (LinearEntity3D, Point3D)):
             raise TypeError('Entity must be two dimensional, not three dimensional')


Test patch:
diff --git a/sympy/geometry/tests/test_ellipse.py b/sympy/geometry/tests/test_ellipse.py
index 385213f427..7b8794075f 100644
--- a/sympy/geometry/tests/test_ellipse.py
+++ b/sympy/geometry/tests/test_ellipse.py
@@ -155,7 +155,7 @@ def test_ellipse_geom():
     assert c1.is_tangent(e1) is True
     assert c1.is_tangent(Ellipse(Point(2, 0), 1, 1)) is True
     assert c1.is_tangent(
-        Polygon(Point(1, 1), Point(1, -1), Point(2, 0))) is True
+        Polygon(Point(1, 1), Point(1, -1), Point(2, 0))) is False
     assert c1.is_tangent(
         Polygon(Point(1, 1), Point(1, 0), Point(2, 0))) is False
     assert Circle(Point(5, 5), 3).is_tangent(Circle(Point(0, 5), 1)) is False
@@ -470,7 +470,16 @@ def test_is_tangent():
     assert e1.is_tangent(Polygon((-3, -5), (-3, 5), (3, 5), (3, -5))) is True
     assert c1.is_tangent(Polygon((-3, -5), (-3, 5), (3, 5), (3, -5))) is False
     assert e1.is_tangent(Polygon((0, 0), (3, 0), (7, 7), (0, 5))) is False
-    assert e1.is_tangent(Polygon((3, 12), (3, -12), (6, 5))) is True
+    assert e1.is_tangent(Polygon((3, 12), (3, -12), (6, 5))) is False
+    assert e1.is_tangent(Polygon((3, 12), (3, -12), (0, -5), (0, 5))) is False
+    assert e1.is_tangent(Polygon((3, 0), (5, 7), (6, -5))) is False
+    assert c1.is_tangent(Segment((0, 0), (-5, -2))) is False
+    assert e1.is_tangent(Segment((-3, 0), (3, 0))) is False
+    assert e1.is_tangent(Segment((-3, 5), (3, 5))) is True
+    assert e1.is_tangent(Polygon((0, 0), (5, 5), (5, -5))) is False
+    assert e1.is_tangent(Polygon((-100, -50), (-40, -334), (-70, -52))) is False
+    assert e1.is_tangent(Polygon((-3, -5), (-3, 5), (3, 5), (3, -5))) is True
+    assert c1.is_tangent(Polygon((-3, -5), (-3, 5), (3, 5), (3, -5))) is False
     assert e1.is_tangent(Polygon((3, 12), (3, -12), (0, -5), (0, 5))) is False
     assert e1.is_tangent(Polygon((3, 0), (5, 7), (6, -5))) is False
     raises(TypeError, lambda: e1.is_tangent(Point(0, 0, 0)))