I created a small canvas js script and draw outline on shape here is the script
context.beginPath();
context.moveTo(coordinates[0].x, coordinates[0].y);
for (let index = 1; index < coordinates.length; index++) {
context.lineTo(coordinates[index].x, coordinates[index].y);
}
context.lineWidth = 2;
context.strokeStyle = "red";
context.fillStyle = "rgba(255, 0, 0, 0.3)";
context.fill()
context.closePath();
context.stroke();
But i am unable to get its width and height of shape, actually i want to display and line as tooltip for user reference.
Here i attach image you can see black line on top of Dice (i did for your reference in photoshop). i want to show that line.
i am noob, if any one can help me with example code that would be great.
2
Answers
You can get the min/max X and Y like this:
You can calculate height and width using the min and max values.
If your polygon looks like following, this could be the fastest solution.