Draw a self intersecting polygon on the HTML Canvas

雨燕双飞 提交于 2020-01-01 09:54:34

问题


I'm looking for a way to draw a self intersecting polygon with holes, I'm using the HTML Canvas element.

So given 5 points, I want to draw the red one below.

This question is essentially the same thing.

Note: I don't want to do this using line intersections and adding more points, the actual paths I will be using will be curved.


回答1:


You can't draw the first pentagram with a single path in Canvas 2D - the fill rule being used there is even-odd and Canvas fills shapes with the non-zero winding rule.

I think you'll need to compute the intersection points for the corners of the interior pentagon and fill it separately. To achieve the drawing you use as an example, you could fill the pentagram (without stroke lines), fill the internal pentagon (again without stroke lines) then draw the pentagon outline stroke without filling.




回答2:


I'm mostly sure you don't wanna draw it all yourself, do you ? http://gpolo.awardspace.info/fill/main.html shows it being done, but it is all manual work.



来源:https://stackoverflow.com/questions/2145552/draw-a-self-intersecting-polygon-on-the-html-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!