Computational Geometry: Basic structures, Convex Hulls and Randomized Algorithms§

author:David Coeurjolly

Basic elements§

Context§

Objects

Geometrical problems

Theoretical questions

Geometrical Predicate Approach§

Idea

Example

_images/orientation.svg
_images/orientation_circle.svg
Orientation(p,q,r) InCircle(p,q,r,s)

Segment processing§

Cross product

Orientation predicate = sign of the determinant

_images/signdet.png

Orientation(p,q,r) = sign( det\left ( \vec{pq},\vec{pr} \right ))

\Rightarrow {+, 0, - } output

Notations§

Sometimes, Orientation is defined as the sign of the determinant of the following matrix

\left [ \begin{array}{ccc} 1 & p_x & p_y\\1 & q_x & q_y\\1& r_x &r_y\end{array}\right]

Use-case 1: Detect segment intersection§

Problem

Given \{p_1,p_2,p_3,p_4\}, decide if [p_1p_2] intersects [p_3p_4]

Algorithm

Robustness§

Orientation predicate implementation

<CF Robustness CGAL>

\Rightarrow Error control, filtered predicates, formal rewritting, interval computations …

Convex Hulls§

Convex Hull 1: Graham’s Scan§

Step 1

Given a set of point \{p_0,\ldots,p_n\} in \mathbb{R}^2,

Implementation

Step 1 is in O(N\log N)

Convex Hull 1: Graham’s Scan 2§

Step 2

Algo

Push(p0) to S
Push(p1) to S
Push(p2) to  S
For i from 3 to N
  While the angle (head(S / {head(S)}) , head(S), p_i) is convex
    Pop(S);
  Push(p_i) to S;

Step 2 is in O(N)

Illustration§

_images/graham2.PNG _images/graham3.PNG _images/graham4.PNG

Illustration§

_images/grahamend.PNG

Graham’s scan§

Convex Hull 2: QuickHull§

Idea Recursive approach with decimation principle

_images/quickhull.PNG
function  QuickHull(Set S, Point pLeft, Point pRight)
{
  if S == {pLeft, pRight} return edge [pLeft,pRight]

  pH = FurthestPoint(S, pLeft, pRight)
  S1 = points of S on the left of vector [pLeft,pH]
  S2 = points of S on the right of vector [pH,pRight]

  return QuickHull(S1,pLeft,pH) + QuickHull(S2,pH,pRight)
}
//starting from two points on the convex hull (details skipped but not tricks here)

QuickHull is in O(N^2) (but really fast)

Dynamic convex hulls§

Problem we want to update CH(S + {p}) from CH(S)

_images/supportline.png _images/supportline2.png

Supporting lines can be extracted in O(\log N) with Orientation predicate

\Rightarrow incremental convex hull in O(N \log N)

Specific convex hulls: Simple polygonal chain§

Problem settings Let \{s_0, \ldots, s_{n-1}\} be a simple polygonal chain (no self-intersection)

Solution Melkman’s algorithm

_images/melkman.png

Melkman’s algorithm§

//Init
if Orientation(v0,v1,v2) then D=<v2,v0,v1,v2> else D=<v2,v1,v0,v2>
i = 3;

while (i<N)
{
  //Simple case, no update required
  while (Orientation(d_{t-1},d_t,vi)) and Orientation(d_b,d_{b+1}, vi))
    i++;

  //Ok, vi is exterior to Q_i, we restore the convexity
  repeat
    pop(d_t)
  until Orientation(d_{t-1},d_t,vi);
  push(vi);
  repeat
    remove(d_b)
  until Orientation(vi,d_b,d_{b+1});
  insert(vi);
}
//Done

Thanks to the simplicity of the polygonal chain, correctness can be demonstrated with O(N) complexity

Convex hulls in higher dimension§

Given a set S pf N points in space

Dimension 2 CH(S) has O(N) vertices/edges

Dimension 3

Dimension d

Convex hull algorithms in 3-Space§

Visibility based approaches

Extract visibility horizon and update the convex hull

_images/gift-1.png _images/gift-2.png

Output sensitive algorithms§

Idea

Computational cost proportional to the output size.

Dim 2

Dim 3

Dim d

QuickHull in 3-space§

Simple construction

Randomization on Computational Geometry§

Introduction§

Idea

For some algorithms, randomized algorithm can be defined with expected computational cost

E.g. “the expected computational cost of algorithm A is O(N)”

Keep in mind that

Why?

Example: Binary Space Partitions§

Idea

Given a set of segments \{s_i\}, we construct a binary tree partitioning the space such that each segment splits the space by its associated line l(s_i)

_images/bsp-1.png

Simple Tree construction§

S=\{s_1,\ldots,s_n\}

function 2DBSP(S)
{
   if (Card(S) <= 1)
      Create a tree T consisting of a single leaf node containing S
   else
   {
     //We split along l(s1) (first element of S)
     S+ = { s\cap l(s1)+, s in S);
     S- = { s\cap l(s1)-, s in S);
     T+ = 2DBSP(S+)
     T- = 2DBSP(S-)
     Create a tree T with root node v (S(v)={s in S, s subset l(s1)})
     and sub-trees T+ and T-
   }
   return T;
}

Randomization§

function Random2DBSP(S)
{
  Generate random permutation S'=s1, ..., sn of the set S
  return 2DBSP(S')
}

Nice, but does it help to bound the number of fragments ?

Main result

Thm.

The expected number of fragments generated by Random2DBSP is O(n\log n)

(instead of O(n^2) with naive approach)

Observation: The order matters§

_images/bsp-2.png

Proof§

(dist_{s_i}(s_j)=+\infty if l(s_i) does not intersect s_j)

_images/bsp-3.png

Let us define k = dist_{s_i}(s_j) and let s_{j1}, s_{j2}, \ldots, s_{jk} be such segments between s_i and s_j.

Question what is the probability that l(s_i) cut s_j ?

Proof (bis)§

Some segments s_m may exist such that l(s_m) shield s_j from s_i. Hence, we do not have an equality in the Expectation expression:

E[\text{number of fragments generated by }s_i]
\leq
\sum_{j\neq i} \frac{1}{dist_{s_i}(s_j) + 2}\\
\quad\quad\quad \leq
2\sum_{k=0}^{n-2} \frac{1}{k + 2}\\
   \quad\quad\quad \leq  2 \ln(n)

\Rightarrow By linearity of expectation, the expected number of segments is n + 2n \ln(n)