Find the intersection of two lines: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 416: | Line 416: | ||
5 5 |
5 5 |
||
</pre> |
</pre> |
||
=={{header|Arturo}}== |
|||
{{trans|Go}} |
|||
<lang rebol>define :point [x,y][] |
|||
define :line [a, b][ |
|||
init: [ |
|||
this\slope: (this\b\y-this\a\y)/(this\b\x-this\a\x) |
|||
this\yInt: this\a\y - this\slope * this\a\x |
|||
] |
|||
] |
|||
evalX: function [line, x][ |
|||
line\yInt + line\slope * x |
|||
] |
|||
intersect: function [line1, line2][ |
|||
x: (line2\yInt - line1\yInt) // (line1\slope - line2\slope) |
|||
y: evalX line1 x |
|||
to :point @[x y] |
|||
] |
|||
l1: to :line @[to :point [4.0 0.0] to :point [6.0 10.0]] |
|||
l2: to :line @[to :point [0.0 3.0] to :point [10.0 7.0]] |
|||
print intersect l1 l2</lang> |
|||
{{out}} |
|||
<pre>[x:5.0 y:5.0]</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |