@Tiny-Leaf
Try the following code. The length of three segments should be same.
drawLine(ctx, 50, 50, 150, 50);
drawLine(ctx, 150, 50, 50, 50);
drawLine(ctx, 150, 100, 50, 100);
function drawLine(ctx, x1, y1, x2, y2)
{
ctx.beginPath()
ctx.moveTo(x1, y1)
ctx.lineTo(x2, y2)
ctx.stroke()
}
BTW: you may somehow avoid to draw a line twice if possible. It is not efficient.