Assume you've got a triangle defined by three points:
a = {x:10, y:20}
b = {x:60, y:70}
c = {x:99, y:30}
This is how to draw it:
ctx.beginPath();
ctx.moveTo(a.x, a.y);
ctx.lineTo(b.x, b.y);
ctx.lineTo(c.x, c.y);
ctx.stroke()
ctx.closePath();
Now let's extend both sides. The first line is given by:
slope1 = (a.y - b.y) / (a.x - b.x)
intercept1 = b.y - (slope1 * b.x)
similarly, the second one:
slope2 = (c.y - b.y) / (c.x - b.x)
intercept2 = b.y - (slope2 * b.x)
Select endpoints on the other side of the intersection point:
if(!Number.isFinite(slope1)) end1 = {x:b.x, y:b.y*2-a.y}
else if(!slope1) end1 = {x:b.x*2-a.x, y:b.y}
else end1 = {x:b.x*2-a.x, y:(b.x*2-a.x)*slope1+intercept1 }
if(!Number.isFinite(slope2)) end2 = {x:b.x, y:b.y*2-c.y}
else if(!slope2) end2 = {x:b.x*2-c.x, y:b.y}
else end2 = {x:b.x*2-c.x, y:(b.x*2-c.x)*slope2+intercept2 }
and draw the extensions:
ctx.beginPath();
ctx.setStrokeColor('red');
ctx.moveTo(b.x, b.y);
ctx.lineTo(end1.x, end1.y);
ctx.moveTo(b.x, b.y);
ctx.lineTo(end1.x, end1.y);
ctx.stroke();
ctx.closePath();
http://jsfiddle.net/K549H/10/