[1]


Task

Find the point of intersection of two lines in 2D.



The 1st line passes though    (4,0)    and    (6,10) .

The 2nd line passes though    (0,3)    and    (10,7) .




 
Module Lineintersection (lineAtuple, lineBtuple) {
	class line {
	private:
		slop, k
	public:
		function f(x) {
			=x*.slop-.k
		}
		function intersection(b as line) {
			if b.slop==.slop then
				=(,)
			else
				x1=(.k-b.k)/(.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<=(y1-y2)/(x1-x2)
			.k<=x1*.slop-y1
		}
	}
	M=line(!lineAtuple)
	N=line(!lineBtuple)
	Print M.intersection(N)
}
Lineintersection (4,0,6,10), (0,3,10,7)  ' print   5  5
 