Find the intersection of two lines: Difference between revisions
Content added Content deleted
m (Add error message to emacs lisp) |
(add lambdatalk code) |
||
Line 1,580: | Line 1,580: | ||
{-Infinity, -Infinity} |
{-Infinity, -Infinity} |
||
</pre> |
</pre> |
||
=={{header|Lambdatalk}}== |
|||
{{trans|Python}} |
|||
<syntaxhighlight lang="scheme"> |
|||
{def line_intersect |
|||
{def line_intersect.sub |
|||
{lambda {:111 :121 :112 :122 :211 :221 :212 :222} |
|||
{let { {:x :111} {:y :121} |
|||
{:z {- {* {- :222 :221} {- :112 :111}} |
|||
{* {- :212 :211} {- :122 :121}} } } |
|||
{:a {- :112 :111}} {:b {- :122 :121}} |
|||
{:c {- :212 :211}} {:d {- :222 :221}} |
|||
{:e {- :121 :221}} {:f {- :111 :211}} |
|||
{:g {- :121 :211}} {:h {- :122 :121}} |
|||
} {if {> :z 0} |
|||
then {A.new ∞ ∞} |
|||
else {let { {:x :x} {:y :y} {:a :a} {:b :b} |
|||
{:t1 {/ {- {* :c :e} {* :d :f}} :z} } |
|||
{:t2 {/ {- {* :a :g} {* :h :f}} :z} } |
|||
} {if {and {>= :t1 0} {<= :t1 1} {>= :t2 0} {<= :t2 1}} |
|||
then {A.new {+ :x {* :t1 :a}} {+ :y {* :t1 :b}} } |
|||
else {A.new ∞ ∞}} }}}}} |
|||
{lambda {:1 :2} |
|||
{line_intersect.sub |
|||
{A.first {A.first :1}} {A.last {A.first :1}} |
|||
{A.first {A.last :1}} {A.last {A.last :1}} |
|||
{A.first {A.first :2}} {A.last {A.first :2}} |
|||
{A.first {A.last :2}} {A.last {A.last :2}} }}} |
|||
-> line_intersect |
|||
{line_intersect {A.new {A.new 4 0} {A.new 6 10}} |
|||
{A.new {A.new 0 3} {A.new 10 7}}} |
|||
-> [5,5] |
|||
{line_intersect {A.new {A.new 4 0} {A.new 6 10}} |
|||
{A.new {A.new 0 3} {A.new 10 7.1}}} |
|||
-> [5.010893246187364,5.05446623093682] |
|||
{line_intersect {A.new {A.new 1 -1} {A.new 4 4}} |
|||
{A.new {A.new 2 5} {A.new 3 -2}}} |
|||
-> [2.5,1.5] |
|||
{line_intersect {A.new {A.new 0 0} {A.new 0 0}} |
|||
{A.new {A.new 0 3} {A.new 10 7}}} |
|||
-> [∞,∞] |
|||
{line_intersect {A.new {A.new 0 0} {A.new 1 1}} |
|||
{A.new {A.new 1 2} {A.new 4 5}}} |
|||
-> [∞,∞] |
|||
</syntaxhighlight> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |