Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick...

18
Computational Computational Geometry Geometry Convex Hulls Convex Hulls Robust Geometric Primitives Robust Geometric Primitives Degeneracy and Stability Degeneracy and Stability Nick Pilkington Nick Pilkington

Transcript of Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick...

Page 1: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Computational Computational GeometryGeometry

Convex HullsConvex HullsRobust Geometric PrimitivesRobust Geometric Primitives

Degeneracy and StabilityDegeneracy and Stability

Nick PilkingtonNick Pilkington

Page 2: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Convex HullConvex Hull

Page 3: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Convex HullConvex Hull

Page 4: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

IdentifyingIdentifying

Two points furthest distance from each other.Two points furthest distance from each other. Minimum set of points enclosing…Minimum set of points enclosing… Ideas of fencing, encompassing or enclosingIdeas of fencing, encompassing or enclosing Diameter, furthest pair, longest distance between…Diameter, furthest pair, longest distance between…

Page 5: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

AlgorithmsAlgorithms Jarvis March Jarvis March

O(n.h)O(n.h) Graham ScanGraham Scan

O(n.log n)O(n.log n)

Page 6: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Jarvis MarchJarvis March

Pick a point that you know to be on the convex hull.Pick a point that you know to be on the convex hull. To determine the next point on the hull, loop through all points and To determine the next point on the hull, loop through all points and

find the one that forms the minimum sized anticlockwise angle off find the one that forms the minimum sized anticlockwise angle off the horizontal axis from the previous point. the horizontal axis from the previous point.

Continue until you encounter the first pointContinue until you encounter the first point

Page 7: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Pros and ConsPros and Cons

ProsPros Easy to programEasy to program

Cons Cons Slow! Possibly O(nSlow! Possibly O(n22))

Page 8: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Graham ScanGraham Scan Find a point you know to be on the convex hull. (Lower y coordinate)Find a point you know to be on the convex hull. (Lower y coordinate) Sort all other points angularly around this point (anti clockwise), by calculating the Sort all other points angularly around this point (anti clockwise), by calculating the

angle that each point makes with the x axis (within the range 0 to 360 degrees) angle that each point makes with the x axis (within the range 0 to 360 degrees) Add the first two points to the hull.Add the first two points to the hull. For every other point except the last point For every other point except the last point Make it the next point in the convex hull Make it the next point in the convex hull Check to see if the angle it forms with the previous two points is greater than 180 Check to see if the angle it forms with the previous two points is greater than 180

degrees degrees As long as the angle formed with the last two points is greater than 180 degrees, remove As long as the angle formed with the last two points is greater than 180 degrees, remove

the previous point the previous point To add the last point To add the last point

Perform the deletion above, Perform the deletion above, Check to see if the angle the last point forms with the previous point and the first point is Check to see if the angle the last point forms with the previous point and the first point is

greater than 180 degrees or if the angle formed with the last point and the first two points is greater than 180 degrees or if the angle formed with the last point and the first two points is greater than 180 degrees. greater than 180 degrees.

If the first case is true, remove the last point, and continue checking with the next-to-last If the first case is true, remove the last point, and continue checking with the next-to-last point. point.

If the second case is true, remove the first point and continue checking. If the second case is true, remove the first point and continue checking. Stop when neither case is true. Stop when neither case is true.

Page 9: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Graham ScanGraham Scan

10

5

9 6

11

2

3

8

4

7

1

Page 10: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Pros and ConsPros and Cons

Pros Pros FastFast Relatively Easy to ProgramRelatively Easy to Program

ConsCons Bit fiddly to programBit fiddly to program

Page 11: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Robust Geometric PrimitivesRobust Geometric Primitives

Area of a TriangleArea of a Triangle Line / Line Segment IntersectionLine / Line Segment Intersection Point in PolygonPoint in Polygon Area of a Polygon Area of a Polygon Pitfalls, Arithmetic Accuracies, Exceptions.Pitfalls, Arithmetic Accuracies, Exceptions.

Page 12: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Area of a TriangleArea of a Triangle

Heron’s Formula Heron’s Formula Area = Sqrt(s(s-a)(s-b)(s-c)), Area = Sqrt(s(s-a)(s-b)(s-c)), where s = (a+b+c)/2 where s = (a+b+c)/2 Determinant / Cross ProductDeterminant / Cross Product

Page 13: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Line/Line SegmentLine/Line Segment

Line / Line SegmentLine / Line SegmentAbove and Below TestAbove and Below TestUse the signed area of the triangleUse the signed area of the triangle

Line Segment / Line SegmentLine Segment / Line SegmentSame a s above, however TWO checks are necessary!Same a s above, however TWO checks are necessary!

Page 14: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Point in PolygonPoint in Polygon

Extend the point in a random direction forming a ray.Extend the point in a random direction forming a ray. Find the number of times the ray intersects an edge of the polygon.Find the number of times the ray intersects an edge of the polygon. Even number of intersections = outsideEven number of intersections = outside Odd number of intersection = insideOdd number of intersection = inside

Algorithm generalizes to 3 dimensions!

Page 15: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Area of PolygonArea of PolygonArea of polygonArea of polygonThe area of a polygon with vertices (The area of a polygon with vertices (xx 1, 1, yy 1), ..., ( 1), ..., (xx n, n, yy n) is equal to the n) is equal to the determinant: determinant:

 1   | x1 x2 . . . xn  | 1   | x1 x2 . . . xn  |---  |                |---  |                | 2   |  y1 y2 . . . yn | 2   |  y1 y2 . . . yn |

This formula generalizes to compute d! times the volume of a simplex in d This formula generalizes to compute d! times the volume of a simplex in d dimensions.dimensions.

Areas and volumes are signed!Areas and volumes are signed!

Page 16: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

Area of a PolygonArea of a Polygon

TriangulationTriangulation Monte Carlo MethodsMonte Carlo Methods

Page 17: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

PitfallsPitfalls

Degeneracy Degeneracy Ignore It !Ignore It ! Deal with It!Deal with It!

Numerical Stability Numerical Stability Precision!Precision! Rounding Errors!Rounding Errors!

Page 18: Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.

QuestionsQuestions IOI 2003 Day 2 :: BoundaryIOI 2003 Day 2 :: Boundary Given a rectangular field with fence posts 1 meter apart along its Given a rectangular field with fence posts 1 meter apart along its

perimeter. An number of rocks represented by polygons in the field. perimeter. An number of rocks represented by polygons in the field. A viewers position. Calculate the number of fence posts that a A viewers position. Calculate the number of fence posts that a person at the viewers position can see, unobstructed by rocks in the person at the viewers position can see, unobstructed by rocks in the field. field.

O(N.R)O(N.R) 72~80%72~80%O(R log R + N Log d) 100%O(R log R + N Log d) 100%

***Looking at the top 20 places from IOI 2003 only 6 of them scored ***Looking at the top 20 places from IOI 2003 only 6 of them scored more than 72% in this problem. ***more than 72% in this problem. ***