Find the intersection of two lines: Difference between revisions
Content added Content deleted
(→{{header|C++}}: minor change) |
No edit summary |
||
Line 1,144: | Line 1,144: | ||
{{out}} |
{{out}} |
||
<pre>5 5</pre> |
<pre>5 5</pre> |
||
=={{header|M2000 Interpreter}}== |
|||
<lang M2000 Interpreter> |
|||
Module Lineintersection (lineAtuple, lineBtuple) { |
|||
class line { |
|||
private: |
|||
slop, Xz, Yz |
|||
public: |
|||
function f(x) { |
|||
=.slop*(x-.xz)+.yz |
|||
} |
|||
function intersection(b as line) { |
|||
if b.slop==.slop then |
|||
=(,) |
|||
else |
|||
x1=(b.slop*b.xz+b.yz+.slop*.xz-.yz)/(.slop-b.slop) |
|||
=(x1, .f(x1)) |
|||
end if |
|||
} |
|||
Class: |
|||
module line { |
|||
read x1, y1, x2, y2 |
|||
if x1==x2 then error "wrong input" |
|||
if x1>x2 then swap x1,x2 : swap y1, y2 |
|||
(.slop, .xz, .yz)=((y1-y2)/(x1-x2), x1, y1) |
|||
} |
|||
} |
|||
M=line(!lineAtuple) |
|||
N=line(!lineBtuple) |
|||
Print M.intersection(N) |
|||
} |
|||
Lineintersection (4,0,6,10), (0,3,10,7) ' print 5 5 |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
5 5 |
|||
</pre> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |