Find the intersection of two lines: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 11: | Line 11: | ||
<br>The 2<sup>nd</sup> line passes though <big> (0,3) </big> and <big> (10,7)</big> . |
<br>The 2<sup>nd</sup> line passes though <big> (0,3) </big> and <big> (10,7)</big> . |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F line_intersect(Ax1, Ay1, Ax2, Ay2, Bx1, By1, Bx2, By2) |
|||
V d = (By2 - By1) * (Ax2 - Ax1) - (Bx2 - Bx1) * (Ay2 - Ay1) |
|||
I d == 0 |
|||
R (Float.infinity, Float.infinity) |
|||
V uA = ((Bx2 - Bx1) * (Ay1 - By1) - (By2 - By1) * (Ax1 - Bx1)) / d |
|||
V uB = ((Ax2 - Ax1) * (Ay1 - By1) - (Ay2 - Ay1) * (Ax1 - Bx1)) / d |
|||
I !(uA C 0.0..1.0 & uB C 0.0..1.0) |
|||
R (Float.infinity, Float.infinity) |
|||
V x = Ax1 + uA * (Ax2 - Ax1) |
|||
V y = Ay1 + uA * (Ay2 - Ay1) |
|||
R (x, y) |
|||
V (a, b, c, d) = (4.0, 0.0, 6.0, 10.0) |
|||
V (e, f, g, h) = (0.0, 3.0, 10.0, 7.0) |
|||
V pt = line_intersect(a, b, c, d, e, f, g, h) |
|||
print(pt)</lang> |
|||
{{out}} |
|||
<pre> |
|||
(5, 5) |
|||
</pre> |
|||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |