Algorithm to split self-intersected Path2D into several not self-intersected paths?

前端 未结 3 1863
眼角桃花
眼角桃花 2021-02-06 13:24

I need to get rid of self-intersections in a shape. Shape is constructed from an array of points, so all segments of that shape are lines. (only lines, no curves and arcs

3条回答
  •  遥遥无期
    2021-02-06 13:54

    I bookmarked your question/answer in case I had to implement something similar myself, but then I found the GEOS project which has a simple way of achieving this. I'm calling GEOS from Python/Django, but the whole thing is based on JTS (Java Topology Suite) so I'd start there and treat the following Python as psuedo-code.

    Basically, the UNION operation will split a line into simply connected parts if it is not simply connected (explained here), so UNIONing the line with it's first point does what we need:

    line  = LineString(list_of_lines_x_y_coordinates)
    # union with first point splits into MultiLineString containing segments
    segments = line.union(line[0]) 
    

提交回复
热议问题