Find the intersection of two lines: Difference between revisions
Content added Content deleted
m (→{{header|M2000 Interpreter}}: more compact) |
|||
Line 1,149: | Line 1,149: | ||
class line { |
class line { |
||
private: |
private: |
||
slop, |
slop, k |
||
public: |
public: |
||
function f(x) { |
function f(x) { |
||
=.slop |
=x*.slop-.k |
||
} |
} |
||
function intersection(b as line) { |
function intersection(b as line) { |
||
Line 1,158: | Line 1,158: | ||
=(,) |
=(,) |
||
else |
else |
||
x1=(-b. |
x1=(.k-b.k)/(.slop-b.slop) |
||
=(x1, .f(x1)) |
=(x1, .f(x1)) |
||
end if |
end if |
||
Line 1,167: | Line 1,167: | ||
if x1==x2 then error "wrong input" |
if x1==x2 then error "wrong input" |
||
if x1>x2 then swap x1,x2 : swap y1, y2 |
if x1>x2 then swap x1,x2 : swap y1, y2 |
||
.slop<=(y1-y2)/(x1-x2) |
|||
.k<=x1*.slop-y1 |
|||
} |
} |
||
} |
} |