C++: Introduction & Data Types

Download Report

Transcript C++: Introduction & Data Types

Duality
p : y  pxx  py
*
point
p  ( px , py )
line
line
l : y  mx  b
point l *  ( m ,  b )
*
p1
l
p4
p3
p
*
4
 p1 y
l
p2
*
p1 y
p1 x
p1  ( p1 x , p1 y )
*
p2
*
p3
primal plane
dual plane
Collinear Points
p1Point
, p 2 , p 3 collinear on line l
*
1
*
2
dual lines p , p , p
*
3
concurrent at l *
(p )  p
* *
(l )  l
* *
p  l iff l *  p *
p lies above l iff
l
*
lies above p
*
Dual of a Line Segment?
Point
q
p
l
r
s
p
r
*
*
l
q
*
*
Relation to a Parabola
*
y
Dual p of p is the tangent
line of the parabola at p .
2
Point
x
2
Proof
Let p  ( p x , p y ) .
Slope of the tangent: p x .
But dual is line y  p x x  p y ,
p
which has the same slope.
Since p y  p x / 2 ,
dual line.
2
p
*
p  ( p x , p y is
) lies on the
Relation to a Parabola (2)
y
x
2
p  ( px , py )
Point
2
*
q  ( px , py  d )
q'
p
d
q
p : y  pxx  py
q : y  pxx  py  d
*
q ' p  p  q
q' ( px , p y  d )
q
*
p
*
*
*
The dual line q // p and it passes
through q ' .
More on Duality
y
x
2
Construct thedual line of q
without measuring distances:
Point
2
p2
q
*
1) Through q draw two tangent
lines to the parabola.
2) Let p 1 and p 2 be the points
of tangency, respectively.
p1
*
3)
q
The two tangent lines are p
p
*
1
and
*
2
q is the line through
p 1 and p 2 .
*
1
*
2
and p .
p intersect at q  q * passes through p 1 and p 2 .
Back to the Discrepancy Problem
Point
q
p
l( p, q)
# points below l ( p , q )
= #lines strictly above l ( p , q ) *
l( p, q)
p
*
q
*
*
Efficient algorithm exists!
Arrangement of Lines
L: Point
a set of n lines.
A(L): planar subdivision induced by L.
with unbounded edges and faces
Simple arrangement if
no three lines are concurrent.
no two lines are parallel.
edge
vertex
face
Reduction to Line Arrangment
Point
Problem
on points
problem on an arrangement of dual lines.
p
l
p
primal plane
*
q
l
q
*
*
dual plane
Structure of a line arrangement is more apparent than
that of a point set.
Combinatorial Complexity
Point
#vertices + #edges + #faces
Theorem #vertices
#edges
#faces

n ( n  1)
2
n
2
n
2

2

n
1
2
Equality holds if and only if A(L) is simple.
Proof of Complexity
We first show that #vertices, #edges, #faces are maximal when
A(L)Point
is simple and not otherwise.
1) Let l  L be parallel to one or more lines.
small enough
rotation to result
l
l1
in one change
in A(L)
new vertex
l
l1
Complexity increases in this case. (Hence such configuration
cannot be maximal.)
Proof (Cont’d)
2) Supppose
Point
l passes through a vertex.
l1
l1
l
l
translate l
l2
slightly
l2
2 new vertices
3 new edges
1 new face
Since complexity increases, such configuration cannot be
maximal either.
The arrangement with maximal complexity must be simple.
Exact Size of a Simple Alignment
nv 
# vertices
ne 
nf 
# edges
Point
# faces
Any pair of lines intersect .
 n  n ( n  1)
nv    
2
2
#edges on one line = 1 + #intersections on the line
n 1
n e  n  (1  n  1)  n
2
Number of Faces
Pointv 
1. Add a vertex v  at infinity.
2. Connect the two endpoints of
every edge to v  .
No edge crossing will be generated.
A planar graph, by Euler’s theorem,
( n v  1)  n f  n e  2
n f  2  ( n v  1)  n e
n ( n  1)
2
 2(
 1)  n
2
2
n
n

 1
2
2
Storage of Line Arrangement
Point
Doubly-connected
edge list.
Add a bounding box to contain all vertices in interior.
Construction of DCEL for A(L)
Plane
Pointsweep?
O ( n log n  I log n )  O ( n log n )
2
pairwise intersection
Not optimal!
I  n ( n  1) / 2
Incremental Algorithm
Preprocessing
Point
Compute the bounding box B(L).  ( n )
- n
2
2
intersections.
- leftmost, rightmost, top, bottom intersections.
Add lines
l1 , l 2 ,..., l n one by one.
Update the DCEL after each addition.
Updating the Subdivision
AiPoint
: subdivision due to {l1 , l 2 ,..., l i }
Case 1 enter a face f through edge e.
li
e
g
f
e'
- walk along boundary of f using the
the Next pointer.
- find exit edge e’.
- use its Twin() pointer to enter face g.
Updating the Subdivision
Case 2 leave a face (g) through a vertex (u).
Point
- walk around u to find the next face
(h) intersected by l i
li
g
u
h
Alternatively use Next() and Twin()
pointers,
First Edge of Intersection
How to find the first edge (leftmost edge) intersected by l i ?
Point
It must be an edge on the bounding box B(L).
Just test all edges on B(L).
In case l i is vertical, locate the bottom intersection to start off
traversal.
Ai
has 2 ( i  1)  4 edges on B(L) since each edge intersects it twice.
First intersection edge can be found in O(i) time.