220 likes | 439 Views
Computational Geometry. Ken George COT 4810 4/19/2008. Computational Geometry. Primary purpose was to further computer graphics, computer-aided design, and computer-aided manufacturing Used in several classical problems, as well
E N D
Computational Geometry Ken George COT 4810 4/19/2008
Computational Geometry • Primary purpose was to further computer graphics, computer-aided design, and computer-aided manufacturing • Used in several classical problems, as well • Can be applied to any situation where the problem can be expressed in geometric terms
Three Problem Classes • The field of computational geometry can be divided into three general classes of problems • Static • Geometric Queries • Dynamic
Static Problems • Given input, construct the corresponding output • Examples • Finding the closest pair of points • Determining convex hulls • Polygonal Triangulation • Creating a Voronoi Diagram
Closest Points • Given a set of points, find the closest two • Brute force: O(n2) For every point p For every point q If p!=q and distance(p, q) < distance(p1,p2) p1=p p2=q • Recursive Divide and Conquer: O(nlog2n)
Pseudocode CP(X, Y) if X.length <= 3 return the closest pair else Divide into: XL, YL, XR, YR dL= CP(XL, YL) dR= CP(XR, YR) d = min(dL, dR) Create Y strip d strip= something big for all points a in Y strip for all points b in Y strip “near” a abDist = dist(Y strip[a], Y strip[b]) if abDist = d strip then d strip= abDist Return min(d, d strip )
Convex Hull • Given a set of points, create a minimal convex set which contains all points • The elastic band analogy:
Gift-wrapping Algorithm • Begin at the leftmost point (in this example) • From vertical line, sweep clockwise until point is encountered • Continue sweep from current angle at next point • O(nh) • O(n2)
Graham Scan • Sort points by angle in respect to first point • further sort equal angles by distance • O(n) time if the points are already sorted • O(n logn) otherwise Stack.push(Points[1]); Stack.push(Points[2]); FOR i = 3 TO Points.length WHILE (Stack.length >= 2 and Cross_product(Stack.second, Stack.top, Points[i]) <= 0) Stack.pop; Stack.push(Points[i]);
Graham Scan • Walk points from bottom • Move only counterclockwise • If clockwise move is found, remove last step
Polygonal Triangulation • Breaking a polygon into triangular sections • Can be used for modeling terrain and other objects • Euclidean minimum spanning tree is a subset of the Delaunay Triangulation (naïve runtime O(n2))
Voronoi Diagrams • Given a set of points, partition according to closest point • Many useful applications • http://www.diku.dk/hjemmesider/studerende/duff/Fortune/
Geometric Queries • Geometric searching problems • Given a search space and query set • Examples • Range Searching • Ray Tracing
Range Searching • Determine the number of points inside of a polygonal query section
Ray Tracing • Computer graphics applications • Can simulate accurate reflection and refraction • Functions like backwards photon mapping
Ray Tracing For each pixel in image { Create ray from eyepoint passing through this pixel Initialize NearestT to INFINITY and NearestObject to NULL For every object in scene { If ray intersects this object { If t of intersection is less than NearestT { Set NearestT to t of the intersection Set NearestObject to this object } } } If NearestObject is NULL { Fill this pixel with background color } Else { Shoot a ray to each light source to check if in shadow If surface is reflective, generate reflection ray: recurse If surface is transparent, generate refraction ray: recurse Use NearestObject and NearestT to compute shading function Fill this pixel with color result of shading function } } (Wikipedia)
Dynamic Problems • Modification of a Computational Geometry problem to a dynamic one • Input elements may be added, removed, or modified • Examples • Dynamic Range Search (Geometric Query) • Dynamic Convex Hull (Static Problem)
Variations • A fourth class of problems • Modifications of the previous three classes • Example • Point-in-Polygon • Static or Geometric Query, depending on the situation
Point-in-Polygon • Given a point and a polygon, determine whether or not the point lies within the polygon • Ray casting • Not the same as ray tracing! • Even-odd test
Another PiP test • Computing the winding number • WN !=0 -> point is inside polygon • Doesn’t work well for complex polygons • (Θ(1)-Θ(0))/2π
References • www.cs.wustl.edu/~rlg1/cse502/handouts/fastclosest.pdf • Images. www.commons.wikimedia.org • http://www.diku.dk/hjemmesider/studerende/duff/Fortune/
Homework • What is the winding number for point P in relation to the polygon in the image below?