Hi all,
Let's say I need to put a text in the middle of the area of a triangle.
I can calculate the coordinates of the triangle's center using getBBox():
var triangle = "M0,0 L100,0 100,50 z";
var BBox = triangle.getBBox();
var middle;
middle.x = BBox.x + BBox.width/2;
middle.y =BBox.y + BBox.height/2;
This results in the coordinates (50, 50) which are always on the long side of the triangle.
How can I make sure the calculated "middle" is <inside> the triangle?
The correct coordinates should be approximately: (75, 25).
The code should of course be independent of this particular example, it should work for any kind of shape.