- Two Distinct Point
- Two-point form
so a line should be like
Line { Point1, Point2 }
function check_on_line(l, p)
#check p on l using Two-point form
p1, p2 <- l
return (x - p1.x) * (p2.y - p1.y) == (y - p1.y) * (p2.x - p1.x)
Init: Build a collection(C
) for Line
s and put first Line
with first two Point
into it.
- take a new
Point
p point_count++
to anyLine
inC
withp
on it- if p is not on any
Line
inC
, createLine
s withp
and all formerPoint
s - put new
Line
s intoC
foreach p in input
on_some_line = False
foreach l in C
if check_on_line(l, c)
l.point_count = l.point_count + 1
on_some_line = True
if not on_some_line
foreach _p in input before p
l = build new Line with _p and p
add l to C
It is wrong that newly built Line.point_count = 0
. Because the new Line l
may cross some Line
in C
,
and the cross point may be the in the input points.
In that case, the new Line
should have its point_count = count of former p on it
.
Patched not on_some_line
block
if not on_some_line
foreach _p in input before p
l = build new Line with _p and p
l.point_count = count of point input before p on l
add l to C
Search C
to find the max count.