Skip to content

Commit

Permalink
simplify polygon/ellipse intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
smichr committed Mar 17, 2024
1 parent b0f460f commit 993e3be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
22 changes: 9 additions & 13 deletions sympy/geometry/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,20 +755,16 @@ def is_tangent(self, o):
else:
return False
elif isinstance(o, Polygon):
all_tangents = False
segments = o.sides if isinstance(o, Polygon) else [o]
for segment in segments:
intersect = self.intersection(segment)
if len(intersect) == 1:
if not any(intersect[0] in i for i in segment.points) \
and not any(self.encloses_point(i) for i in segment.points):
all_tangents = True
continue
else:
return False
# True if any tangent and no crossing
saw_tangent = False
for segment in o.sides:
if self.is_tangent(segment):
saw_tangent = True
else:
return False
return all_tangents
intersect = self.intersection(segment)
if intersect:
return False
return saw_tangent
elif isinstance(o, (LinearEntity3D, Point3D)):
raise TypeError('Entity must be two dimensional, not three dimensional')
else:
Expand Down
3 changes: 2 additions & 1 deletion sympy/geometry/tests/test_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ def test_is_tangent():
assert c1.is_tangent(Ray((-3, -22), (15, 20))) is False
assert c1.is_tangent(Ray((9, 20), (9, -20))) is True
assert c1.is_tangent(Ray((2, 5), (9, 5))) is True
assert c1.is_tangent(Segment((2, 5), (9, 5))) is True
assert e1.is_tangent(Segment((2, 2), (-7, 7))) is False
assert e1.is_tangent(Segment((0, 0), (1, 2))) is False
assert c1.is_tangent(Segment((0, 0), (-5, -2))) is False
Expand All @@ -472,7 +473,7 @@ 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 False
assert e1.is_tangent(Polygon((3, 12), (3, -12), (6, 5))) is True # at (3,0)
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
Expand Down

0 comments on commit 993e3be

Please sign in to comment.