javascript polygon intersection

后端 未结 2 917
旧巷少年郎
旧巷少年郎 2021-01-06 12:50

I have used the code in the following : http://www.amphibian.com/blogstuff/collision.html. in the html test file I have changed the the first triangle to

tr         


        
2条回答
  •  旧时难觅i
    2021-01-06 13:07

    Here is my not too complicated implementation of finding the intersection polygon of two polygons.

    It works for convex and concave polygons, but not for complex (self-intersecting) polygons. Algorithm is fairly similar to the one presented in Margalit & Knott.

    Its complexity is about 4*n1*n2, where n1 and n2 are numbers of vertices in polygons whose intersection is being calculated.

    It is a single standalone .js file. A 'Polygon' is regarded any javascript array of 2D Points. A 'Point' is any javascript object with x and y numeric properties.

    Implementing the Union functionality on top of existing one should not be a problem and I will do it probably soon.

    Intersection of 2D polygons

提交回复
热议问题