UMass Lowell Computer Science 91.504
Advanced Algorithms
Computational Geometry
Prof. Karen Daniels
Spring, 2004
O’Rourke Chapter 7
Search & Intersection
Chapter 7
Search & Intersection
Segment-Segment Intersection
Segment-Triangle Intersection
Point in Polygon
Point in Polyhedron
Intersection of Convex Polygons
Intersection of Segments
Intersection of Nonconvex Polygons
Extreme Point of Convex Polygon
Extremal Polytope Queries
Planar Point Location
Demo
Segment/Segment Intersection
http:/cs.smith.edu/~orourke/books/CompGeom/CompGeom.html
Segment-Segment Intersection
Finding the actual intersection point
Approach: parametric vs. slope/intercept
parametric
generalizes to more complex
intersections
Parameterize each segment
Lcd
Lcd
c
C=d-c
Lab
c
b
a
Lab
b
q(t)=c+tC
A=b-a
d
d
a
p(s)=a+sA
Intersection: values of s, t such that p(s) =q(t) : a+sA=c+tC
Segment-Triangle Intersection
Determine if qr intersects plane p containing triangle T.
Let N=(A,B,C) be normal to p
p :(x,y,z)dot(A,B,C)=D
find N using cross-products involving a,b,c
parameterize qr: p(t) = q + t(r-q)
solve for t: t D (q N )
(r q) N
using t, find point of intersection p if it exists
r
p
c
a
T
N
p
b
q
Classify relationship between p and T
p is in T iff it is in a projection* T’ of T
to xy, xz or yz-plane
+-++-
* avoid degeneracy by projecting out largest coordinate
+-+
+++
-+- -++
T’
--+
Demo
Point in Polygon
http:/cs.smith.edu/~orourke/books/CompGeom/CompGeom.html
Point in Polygon
q
P
Winding number
standing at q, turn to follow border of P
sum rotation to create signed angular turn + ccw
divide by 2p
elegant but not practical: O(n) with large constant
- cw
Ray crossings
extend horizontal ray from q
count number of intersections
even
odd
beware
q
with P
q is outside P
q is inside P
P
degenerate intersections!
Compare with using LeftOn test when polygon is convex
O(n)
Point in Polyhedron
Winding number
generalizes to 3D
uses solid angle
(fraction of sphere used by
cone at point)
P
q
Ray crossing
generalizes to 3D
q
inside P if odd
number of
crossings
q outside P if even
number of
crossings
O(rn)
r = number of tries to get
nondegenerate intersection
Algorithm: POINT in POLYHEDRON
Compute bounding radius R
loop forever
r0 = random ray of length R
r = q + r0
crossings = 0
for each triangle T of polyhedron P do
SegTriInt(T, q, r)
if degenerate intersection
then go back to loop
else increment crossings appropriately
if crossings odd
then q is inside P
else q is outside P
Exit
Demo
Convex Polygon Intersection
http:/cs.smith.edu/~orourke/books/CompGeom/CompGeom.html
Intersection of Convex Polygons
For n-vertex P and m-vertex Q, the worstcase size complexity of P Q is in (nm)
For convex P, Q, size is only in O(n m)
and can be computed in O(n m) time
Algorithm: INTERSECTION of CONVEX POLYGONS
/* A is directed edge on P */
Choose A and B arbitrarily
/* B is directed edge on Q */
repeat
/* A, B “chase” each other */
if A intersects B then
/* A, B meet at each */
Check for termination
/* boundary crossing */
Update inside flag
Advance either A or B
depending on geometric conditions
until both A and B cycle their polygons
Handle cases: P Q P Q P Q 0 O(n+m)
Intersection of Segments
Goal: “Output-size sensitive” polygon
intersection algorithm
Core Problem: “Output-size sensitive” line
segment intersection algorithm
Bentley-Ottmann plane sweep: O((n+k)logn) time
k = number of intersection points in output
Intuition: sweep horizontal line downwards
just before intersection, 2 segments are adjacent in sweepline intersection structure
check for intersection only segments that adjacent
event types:
top endpoint of a segment
bottom endpoint of a segment
intersection between 2 segments
Improved to O(nlogn+k) [Chazelle/Edelsbrunner]
Intersection of Nonconvex Polygons
Variation on BentleyOttmann sweep
Maintain status for
each piece of sweep
line
0: exterior to P, Q
P: inside P, outside Q
Q: inside Q, outside P
PQ: inside P , inside Q
For n-vertex P, m-vertex Q, O((n+m)log(n+m)+k) time to compute:
P Q
P Q
P\Q
Extreme Point of Convex Polygon
Algorithm: HIGHEST POINT of CONVEX POLYGON
A Geometric
/* highest point is in [a,b] */
Initialize a and b
repeat forever
Binary Search
c
index midway from a to b
if P[c] is locally highest then return c
A
a
c
if A points up and C points down
then [a,b]
[a,c] /* highest point is in [a,c] */
C
else if A points down and C points up
then [a,b]
[c,b]
/* highest point is in [c,b] */
else if A points up and C points up
B
if P[a] is above P[c]
b
then [a,b]
[a,c]
Unimodality
then [a,b]
[c,b] /* highest point is in [c,b] */
else if A points down and C points down
Allows
if P[a] is below P[c]
Binary Search
then [a,b]
[a,c] /* highest point is in [a,c] */
O(lg n)
then [a,b]
[c,b] /* highest point is in [c,b] */
Stabbing a Convex Polygon
Extreme-Finding algorithm can stab a convex polygon
a
extreme in + u direction
+u
L
y
extreme in - u direction
x
b
If a and b straddle L,
binary search on [a,b] yields x
binary search on [b,a] yields y
O(lg n)
Extremal Polytope Queries
Form sequence of O(log n) simpler
nested polytopes in O(n) time
To answer a query in O(logn)
time:
Find extreme with respect to inner
polytope, then work outwards
Need only check small number of
candidate vertices in next polytope
Key idea:
independent sets in planar graphs
are “large”; vertices of “low” degree
to construct next (inner) polytope,
remove independent set of vertices
deleting constant fraction of
vertices at each step produces
O(logn) polytopes
Algorithm: INDEPENDENT SET
Input: graph G
Output: independent set I
I
0
Mark all nodes of G of degree >= 9
while some nodes remain unmarked
do
Choose an unmarked node v
Mark v and all neighbors of v
I
I U {v}
An independent set of a polytope graph of n vertices
produced by INDEPENDENT SET has size at least n/18
O(log n)
Extremal Polytope Queries
(continued)
To use nested polytope hierarchy to
answer an extreme point query:
Find
extreme with respect to inner
polytope (brute-force search)
Moving from polytope Pi+1 to Pi
Let ai and ai+1 be uniquely highest vertices of
Pi and Pi+1. Then either ai = ai+1 or
ai+1 is the highest among the vertices adjacent to ai
ai is the highest among the parents of the extreme
edges Li+1 and Ri+1
L’i+1 = R’i+1
p’
P’i+1
tetrahedron
projected
onto xz plane
p
Extremal Polytope Queries
(continued)
Algorithm: EXTREME POINT of a POLYTOPE
Input: polytope P and direction vector u
u
Output: vertex a of P extreme in u direction
Construct nested polytope hierarchy P = P0, P1,..., Pk
ak
vertex of Pk extreme in u direction
Compute Lk and Rk
for i = k - 1, k - 2, ...,1, 0 do
ai
extreme vertex among ai+1 and parents of Li+1 and Ri+1
if ai = ai+1 then
p
Pk
P0
for all edges incident to ai do
save extreme edges Li and Ri
else (ai = ai+1) compute Li from Li+1 etc...
After O(n) time and space preprocessing, polytope
extreme-point queries can be answered in O(log n) time each
Planar Point Location
Goal: Given a planar subdivision of n
vertices, preprocess it so that point location
query can be quickly answered.
A polygonal planar subdivision can be
preprocessed in O(n) time and space for
O(log n) query.
2D
version/variant of independent set/nested
approach
Monotone subdivision approach
Randomized trapezoidal decomposition
© Copyright 2026 Paperzz