Counting Convex k-gons in an Arrangement of Line Segments
Martin Fink, Neeraj Kumar and Subhash Suri
University of California, Santa Barbara
Counting Convex k -gons in an Arrangement of Line Segments Martin - - PowerPoint PPT Presentation
Counting Convex k -gons in an Arrangement of Line Segments Martin Fink, Neeraj Kumar and Subhash Suri University of California, Santa Barbara Motivation Consider the following problem from computer vision: Motivation Consider the following
Martin Fink, Neeraj Kumar and Subhash Suri
University of California, Santa Barbara
Consider the following problem from computer vision:
Consider the following problem from computer vision: Given a camera image I representing object boundaries, estimate the number of rectangular objects in the scene.
Consider the following problem from computer vision: Given a camera image I representing object boundaries, estimate the number of rectangular objects in the scene.
◮ Camera image I ⇒ Arrangement A of line segments
Consider the following problem from computer vision: Given a camera image I representing object boundaries, estimate the number of rectangular objects in the scene.
◮ Camera image I ⇒ Arrangement A of line segments ◮ Perspective transformation:
Rectangles in scene ⇒ quadilaterals in image
Consider the following problem from computer vision: Given a camera image I representing object boundaries, estimate the number of rectangular objects in the scene.
◮ Camera image I ⇒ Arrangement A of line segments ◮ Perspective transformation:
Rectangles in scene ⇒ quadilaterals in image
◮ Count all convex quadilaterals (4-gon) in an arrangement
Consider the following problem from computer vision: Given a camera image I representing object boundaries, estimate the number of rectangular objects in the scene.
◮ Camera image I ⇒ Arrangement A of line segments ◮ Perspective transformation:
Rectangles in scene ⇒ quadilaterals in image
◮ Count all convex quadilaterals (4-gon) in an arrangement
Natural generalization to convex k-gons
Given: An arrangement A(S) of line segments S in 2-D
a b c d e
Given: An arrangement A(S) of line segments S in 2-D
a b c d e
A convex k-gon of A(S) is a convex polygon with k sides if:
Given: An arrangement A(S) of line segments S in 2-D
1 2 3 4 5 6 7 a b c d e
A convex k-gon of A(S) is a convex polygon with k sides if:
◮ vertices are a subset of arrangement vertices.
Given: An arrangement A(S) of line segments S in 2-D
1 2 3 4 5 6 7 a b c d e
A convex k-gon of A(S) is a convex polygon with k sides if:
◮ vertices are a subset of arrangement vertices. ◮ sides are part of input segments.
Given: An arrangement A(S) of line segments S in 2-D
1 2 3 4 5 6 7 a b c d e k = 4
A convex k-gon of A(S) is a convex polygon with k sides if:
◮ vertices are a subset of arrangement vertices. ◮ sides are part of input segments.
Given: An arrangement A(S) of line segments S in 2-D
1 2 3 4 5 6 7 a b c d e k = 4
A convex k-gon of A(S) is a convex polygon with k sides if:
◮ vertices are a subset of arrangement vertices. ◮ sides are part of input segments.
Goal: count and report all such k-gons.
◮ Count all k-gons in O(n log n + mn) time and O(n2) space
(for constant k)
◮ Count all k-gons in O(n log n + mn) time and O(n2) space
(for constant k)
◮ Report set of all k-gons K in O(|K|) additional time and
O(mn) additional space
◮ Count all k-gons in O(n log n + mn) time and O(n2) space
(for constant k)
◮ Report set of all k-gons K in O(|K|) additional time and
O(mn) additional space Count in time much faster than the number of k-gons :
◮ Count all k-gons in O(n log n + mn) time and O(n2) space
(for constant k)
◮ Report set of all k-gons K in O(|K|) additional time and
O(mn) additional space Count in time much faster than the number of k-gons : Θ(nk)
⌊ n
k ⌋
◮ Count all k-gons in O(n log n + mn) time and O(n2) space
(for constant k)
◮ Report set of all k-gons K in O(|K|) additional time and
O(mn) additional space Count in time much faster than the number of k-gons : Θ(nk)
⌊ n
k ⌋
◮ Counting k-gons is as hard as the 3SUM problem, for k = 3, 4
A vertical line L intersects at most two sides of a k-gon P.
L span(P, L) = (a, b)
A vertical line L intersects at most two sides of a k-gon P.
a b L P span(P, L) = (a, b)
A vertical line L intersects at most two sides of a k-gon P.
a b L span(P, L) = (a, b) P
A vertical line L intersects at most two sides of a k-gon P.
a b L span(P, L) = (a, b) P
◮ O(n2) distinct spans (w.r.t. L) among all k-gons
A vertical line L intersects at most two sides of a k-gon P.
a b L span(P, L) = (a, b) P
◮ O(n2) distinct spans (w.r.t. L) among all k-gons ◮ Suggests a plane sweep based algorithm, key idea:
A vertical line L intersects at most two sides of a k-gon P.
a b L span(P, L) = (a, b) P
◮ O(n2) distinct spans (w.r.t. L) among all k-gons ◮ Suggests a plane sweep based algorithm, key idea:
◮ Assign a k-gon intersecting L to its span
A vertical line L intersects at most two sides of a k-gon P.
a b L span(P, L) = (a, b) P
◮ O(n2) distinct spans (w.r.t. L) among all k-gons ◮ Suggests a plane sweep based algorithm, key idea:
◮ Assign a k-gon intersecting L to its span ◮ Update count as we sweep L across the plane
L a b
◮ Open j-gons: All j ≤ k sides start left of L
L a b
◮ Open j-gons: All j ≤ k sides start left of L
L a b
◮ Open j-gons: All j ≤ k sides start left of L
◮ σ(a, b, j) : Number of open j-gons with span (a, b)
L a b σ(a, b, 5) = 2
◮ Open j-gons: All j ≤ k sides start left of L
◮ σ(a, b, j) : Number of open j-gons with span (a, b)
L a b
◮ Open j-gons: All j ≤ k sides start left of L
◮ σ(a, b, j) : Number of open j-gons with span (a, b)
◮ Closed k-gons: All k sides end left of L
L a b count = 2
◮ Open j-gons: All j ≤ k sides start left of L
◮ σ(a, b, j) : Number of open j-gons with span (a, b)
◮ Closed k-gons: All k sides end left of L
◮ count: number of k-gons left of L
◮ Set count = 0 and σ(a, b, j) = 0, for all a, b, j
◮ Set count = 0 and σ(a, b, j) = 0, for all a, b, j ◮ Compute all intersections (Event points)
◮ Set count = 0 and σ(a, b, j) = 0, for all a, b, j ◮ Compute all intersections (Event points) ◮ For each event from left to right: Perform Updates
◮ Set count = 0 and σ(a, b, j) = 0, for all a, b, j ◮ Compute all intersections (Event points) ◮ For each event from left to right: Perform Updates ◮ Return count
a b pi L c d
a b pi L c d
◮ Some k-gons complete
a b pi L c d
◮ Some k-gons complete
◮ count += σ(a, b, k)
a b pi L c d
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
a b pi L c d
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
a b pi c d L
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
a b pi c L d
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
◮ For all segments c above a
a b pi c L d
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
◮ For all segments c above a
a b pi c L d
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
◮ For all segments c above a
σ(c, b, j + 1) += σ(c, a, j)
a b pi d L c
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
◮ For all segments c above a
σ(c, b, j + 1) += σ(c, a, j)
◮ For all segments d below b
a b pi c d L
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
◮ For all segments c above a
σ(c, b, j + 1) += σ(c, a, j)
◮ For all segments d below b
a b pi d L c
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
◮ For all segments c above a
σ(c, b, j + 1) += σ(c, a, j)
◮ For all segments d below b
σ(a, d, j + 1) += σ(b, d, j)
a b pi c d L
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
◮ For all segments c above a
σ(c, b, j + 1) += σ(c, a, j)
◮ For all segments d below b
σ(a, d, j + 1) += σ(b, d, j)
Total O(n) time per intersection
a b pi c d L
◮ Some k-gons complete
◮ count += σ(a, b, k)
◮ A 2-gon begins
◮ σ(b, a, 2) = 1
◮ Some j-gons grow into j + 1-gons
◮ For all segments c above a
σ(c, b, j + 1) += σ(c, a, j)
◮ For all segments d below b
σ(a, d, j + 1) += σ(b, d, j)
Total O(n) time per intersection Handles degenerate cases: apply pairwise updates collectively
Goal: Report all k-gons of the output set K.
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2)
Create a vertex for the new open 2-gon
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (b, a, 3)
2
Add an edge for a j-gon growing into j + 1-gon
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (b, a, 3) (b, d, 4)
2 3
Add an edge for a j-gon growing into j + 1-gon
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (b, a, 3) (b, d, 4) (d, a, 2) (e, a, 4)
2 3 4
Add an edge for a j-gon growing into j + 1-gon
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (b, a, 3) (b, d, 4) (d, a, 2) (e, a, 4) Q = { }
2 3 4
Append vertices for completed k-gons to Q
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (b, a, 3) (b, d, 4) (d, a, 2) (e, a, 4) Q = { }
2 3 7 4
Append vertices for completed k-gons to Q
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (d, a, 2) (b, a, 3) (e, a, 4) (b, d, 4)
2 7 4
Q = { }
3
Recursively enumerate all k-gons
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (d, a, 2) (b, a, 3) (e, a, 4) (b, d, 4)
2 7 4
Q = { }
3
Recursively enumerate all k-gons
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (d, a, 2) (b, a, 3) (e, a, 4) (b, d, 4)
2 7 4 3
Q = { }
Recursively enumerate all k-gons
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (d, a, 2) (b, a, 3) (e, a, 4) (b, d, 4)
2 7 4 3
Q = { }
Recursively enumerate all k-gons
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e (c, a, 2) (d, a, 2) (b, a, 3) (e, a, 4) (b, d, 4)
2 7 4 3
Q = { } ×
Only time respecting paths are valid k-gons
Goal: Report all k-gons of the output set K. Keep track of updates using acyclic digraph G = (V , E, L)
1 2 3 4 5 6 7 a b c d e K = {(1, 2, 4, 6), (1, 2, 3, 7)}
Report all k-gons in O(|K|) additional time
Reduction from Point-on-3-lines problem
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines?
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines? 3SUM − → 3-Points-on-line
dual
− − − − → Point-on-3-lines
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines? 3SUM − → 3-Points-on-line
dual
− − − − → Point-on-3-lines
◮ Reduction ensures that no two lines in L are parallel
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines? 3SUM − → 3-Points-on-line
dual
− − − − → Point-on-3-lines
◮ Reduction ensures that no two lines in L are parallel ◮ Compute bounding box B of the arrangement
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines? 3SUM − → 3-Points-on-line
dual
− − − − → Point-on-3-lines
◮ Reduction ensures that no two lines in L are parallel ◮ Compute bounding box B of the arrangement ◮ Clip the lines around B to obtain an arrangement of segments
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines? 3SUM − → 3-Points-on-line
dual
− − − − → Point-on-3-lines
◮ Reduction ensures that no two lines in L are parallel ◮ Compute bounding box B of the arrangement ◮ Clip the lines around B to obtain an arrangement of segments
n
3
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines? 3SUM − → 3-Points-on-line
dual
− − − − → Point-on-3-lines
◮ Reduction ensures that no two lines in L are parallel ◮ Compute bounding box B of the arrangement ◮ Clip the lines around B to obtain an arrangement of segments
n
3
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines? 3SUM − → 3-Points-on-line
dual
− − − − → Point-on-3-lines
◮ Reduction ensures that no two lines in L are parallel ◮ Compute bounding box B of the arrangement ◮ Clip the lines around B to obtain an arrangement of segments
n
3
n
4
Reduction from Point-on-3-lines problem Given a set of lines L in plane, is there a point that lies on 3 lines? 3SUM − → 3-Points-on-line
dual
− − − − → Point-on-3-lines
◮ Reduction ensures that no two lines in L are parallel ◮ Compute bounding box B of the arrangement ◮ Clip the lines around B to obtain an arrangement of segments
n
3
n
4
Does not extend to k ≥ 5
◮ Introduced the k-gon counting problem
◮ Introduced the k-gon counting problem ◮ Algorithm for k-gon counting in O(mn) ∈ O(n3) time
◮ Introduced the k-gon counting problem ◮ Algorithm for k-gon counting in O(mn) ∈ O(n3) time ◮ Reporting in additional O(|K|) time
◮ Introduced the k-gon counting problem ◮ Algorithm for k-gon counting in O(mn) ∈ O(n3) time ◮ Reporting in additional O(|K|) time ◮ 3SUM hardness for k = 3, 4 ⇒ Significantly better than
O(n2) unlikely
◮ Introduced the k-gon counting problem ◮ Algorithm for k-gon counting in O(mn) ∈ O(n3) time ◮ Reporting in additional O(|K|) time ◮ 3SUM hardness for k = 3, 4 ⇒ Significantly better than
O(n2) unlikely
◮ Open question: faster algorithms?