How can I split a Polygon by a Line?

后端 未结 5 1252
小蘑菇
小蘑菇 2020-12-05 01:03

As shown below,

Is it possible to split a Polygon by a Line? (into two Polygons). If the line doesn\'t go all th

5条回答
  •  猫巷女王i
    2020-12-05 01:22

    Its perfectly possible. I am assuming you're using Java2d for this. You have find a method in it called as intersects. Using that you can do this.

    You might have to modify this implementation of polygon and write one more intersects method which passes a Line2D object and customize it so that it passes an array polygons (possible since the same line cut can produce infinite polygons - assume a zigzag polygon) or null.

提交回复
热议问题