Put label in the “center” of an SVG path

前端 未结 3 1300
萌比男神i
萌比男神i 2021-02-05 14:11

I\'m trying to draw a label on a polygon of an svg file. The problem I\'m facing is to find out roughly the center of this polygon to place the label, as the path\'s coordinates

3条回答
  •  终归单人心
    2021-02-05 14:23

    The simplest thing you could try doing is to calculate the center by taking the average of all the points in the polygon. It should work for all but the most irregular of polygons. I've used the same algorithm to good effect in my programs.

    Best of luck.

提交回复
热议问题