Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersection of a line segment with the interior of a polygon #13935

Open
normalhuman opened this issue Jan 15, 2018 · 3 comments
Open

Intersection of a line segment with the interior of a polygon #13935

normalhuman opened this issue Jan 15, 2018 · 3 comments
Labels

Comments

@normalhuman
Copy link
Contributor

normalhuman commented Jan 15, 2018

I understand that the Polygon class treats polygons mostly like curves rather than 2D shapes. Still, there are some methods (like encloses and area) which pertain to the region enclosed by the polygon.

In this direction someone asked about finding the Intersection between Segment and Interior of Polygon in SymPy on Stack Overflow. They wanted specifically the length, but I imagine one may also want to geometric object, union of line segments.

Should there be something like Polygon.fill().intersect(Segment) method, returning the intersection set? (I am not sure about the API here, do we want a FilledPolygon class object returned by Polygon.fill() method?) My answer on SO has a sketch of a possible approach to this.

@normalhuman normalhuman changed the title Length of intersection of a line segment with the interior of a polygon Intersection of a line segment with the interior of a polygon Jan 15, 2018
@smichr
Copy link
Member

smichr commented Jan 16, 2018

I have shied away from such additions because there are much better options available for dealing with filled regions. After a quick look, I think it was shapely that I had looked at before.

One thing we haven't implemented yet is a footprint area which ignores self intersections of segments. (See this repo for a possible routine to use/modify and related discussion here.)

@smichr
Copy link
Member

smichr commented Jan 16, 2018

Oh yes, pyclipper was the other library.

@smichr
Copy link
Member

smichr commented Jan 18, 2023

To include interior points is a matter of adding to the intersection of two objects those vertices that are enclosed by the other object,

def filled_intersection(a, b):
    i = a.intersection(b)
    def pts(a):
        if hasattr(a, 'vertices'):
            return a.vertices
        if isinstance(a, Point):
            return [a]
        if isinstance(a, Segment):
            return a.args
        assert None, 'unrecognized object for points'
    for do in range(2):
        for j in pts(a):
            if b.encloses_point(j):
                i.append(j)
        a,b=b,a
    return convex_hull(*i)

But this will not work when a convex region of one polygon is contained in another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants