Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a self intersecting polygon on the HTML Canvas

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.

like image 891
Lerc Avatar asked Jan 27 '10 08:01

Lerc


1 Answers

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.

like image 63
andrewmu Avatar answered Oct 01 '22 01:10

andrewmu