Find the intersection of two lines: Difference between revisions

Frink
(Frink)
Line 984:
<pre> 5 5
-1.#IND -1.#IND</pre>
 
=={{header|Frink}}==
<lang frink>lineIntersection[x1, y1, x2, y2, x3, y3, x4, y4] :=
{
det = (x1 - x2)(y3 - y4) - (y1 - y2)(x3 - x4)
if det == 0
return undef
 
t1 = (x1 y2 - y1 x2)
t2 = (x3 y4 - y3 x4)
px = (t1 (x3 - x4) - t2 (x1 - x2)) / det
py = (t1 (y3 - y4) - t2 (y1 - y2)) / det
return [px, py]
}
 
println[lineIntersection[4, 0, 6, 10, 0, 3, 10, 7]]</lang>
{{out}}
<pre>
[5, 5]
</pre>
 
 
=={{header|Go}}==
490

edits