How to draw an outline around any line

后端 未结 5 1790
一生所求
一生所求 2020-12-09 06:11

\"enter

So I have a arbitary line (See an example shown in fig 1) made up of n points<

5条回答
  •  Happy的楠姐
    2020-12-09 06:37

    First duplicate each line twice, once on each side at a distance of half the width you want from each original line. That gives you the green lines in the image. Then you need to visit them in order (numbered) and deal with the loose ends.

    line outlining

    When the lines don't meet (2-3, 6-7 and 12-13) you add a line join (in blue). A line join can be a bevel join (2-3) by just connecting the points, or a miter join by extending the lines until they meet (6-7) or a round join by making a curve.

    When the lines do meet, just take the intersection point (blue dots).

    At the line ends, you need to add an end cap (also in blue). An end cap can be a butt cap (8-9) by connecting the points, a projecting cap (1-16) by extending the lines a little before connecting them, or a round cap (not shown).

    The end result is a polygon (or path if it includes round joins) that you can then stroke or fill.

提交回复
热议问题