computational geometry for the tablet pc

33
Computational Geometry for the Tablet PC CSE 490ra

Upload: nike

Post on 05-Feb-2016

59 views

Category:

Documents


0 download

DESCRIPTION

Computational Geometry for the Tablet PC. CSE 490ra. Overview. SUB: Ask for submission of a picture. Computational Geometry on the Tablet PC Geometric primitives Intersections Polygons Convexity. Tablet Geometry. SUB: What is Points[6.4]?. Basic structure – Stroke: sequence of points - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computational Geometry for  the Tablet PC

ComputationalGeometry for the Tablet PC

CSE 490ra

Page 2: Computational Geometry for  the Tablet PC

Overview Computational

Geometry on the Tablet PC

Geometric primitives

Intersections Polygons Convexity

Page 3: Computational Geometry for  the Tablet PC

Tablet Geometry Basic structure –

Stroke: sequence of points Himetric

coordinates Sampled 150 times

per second

Coordinates stored in an array Points

Page 4: Computational Geometry for  the Tablet PC

Computational Geometry Algorithms for geometric computation Numerical issues with coordinates Importance of degenerate cases

Examples of degenerate cases Three lines intersecting at a point Segments overlapping Three points co-linear

Page 5: Computational Geometry for  the Tablet PC

Basic geometry Point

p Line segment

(p1, p2) Distance

Dist(p1, p2) Basic Test

LeftOf(p1, p2, p3) CCW(p1, p2, p3)

p1

p1

p3

p2

p2

p

Page 6: Computational Geometry for  the Tablet PC

Distance computation Avoid computing square root when

possible Example: find closest point to q

closestSoFar = p1; d = Dist(p1, q);for k = 2 to n {

d1 = Dist(pk, q)if (d1 < d){

closestSoFar = pk; d = d1;

}}

Page 7: Computational Geometry for  the Tablet PC

Counter Clockwise Test CCW(p1, p2, p3)public static bool CcwTest(Point p1, Point p2, Point p3){ int q1 = (p1.Y - p2.Y)*(p3.X - p1.X); int q2 = (p2.X - p1.X)*(p3.Y - p1.Y); return q1 + q2 < 0; }

Page 8: Computational Geometry for  the Tablet PC

Segment intersection Find intersection of (p1,p2) and (p3,p4)

Q = p1 + (1-)p2 Q = p3 + (1-)p4

Solve for , Two equations, two unknowns Intersect if 0 < < 1 and 0 < < 1

Derived points In general, try to avoid computing derived

points in geometric algorithms

Page 9: Computational Geometry for  the Tablet PC

Problem Determine if two line segments (p1, p2) and

(p3,p4) intersect just using CCW Tests

Page 10: Computational Geometry for  the Tablet PC

Making intersection test more efficient Take care of easy

cases using coordinate comparisons

Only use CCW tests if bounding boxes intersect

Page 11: Computational Geometry for  the Tablet PC

Computing intersections Given k strokes, find

all intersections Given a stroke, find

self intersections Break into segments,

and find all pairwise intersections

How many self intersections can a single stroke with n points have?

Page 12: Computational Geometry for  the Tablet PC

Segment intersection algorithm

Run time O(nlog n + Klog n) for finding K intersections Sweepline Algorithm

3

12

4

5

6

7

Page 13: Computational Geometry for  the Tablet PC

Sweepline Algorithm Event queue

Start Segment (S2) End Segment (E2) Intersection (I2,4)

Move sweepline to next event

Maintain vertical order of segments as line sweeps across

Start Segment Insert in list Check above and below

for intersection End Segment

Remove from list Check newly adjacent

segments for intersection

Intersection Reorder segments Check above and below

for intersection

Page 14: Computational Geometry for  the Tablet PC

Sweepline example3

12

4

5

6

7

Page 15: Computational Geometry for  the Tablet PC

Activity: Identify when each of the intersections is detected

A

B

C

D

E

F

Page 16: Computational Geometry for  the Tablet PC

Polygons Sequence of points representing a

closed path Simple polygon – closed path with

no self intersections

Page 17: Computational Geometry for  the Tablet PC

Polygon inclusion test Is the point q inside the Polygon P?

Page 18: Computational Geometry for  the Tablet PC

Convexity Defn: Set S is convex if whenever

p1, and p2 are in S, the segment (p1, p2) is contained in S

Page 19: Computational Geometry for  the Tablet PC

Convex polygons P = {p0, p1, . . . pn-1} P is convex if

CCW(pi, pi+1, pi+2) for all I Interpret subscripts mod n Also holds for CW (depending on how

points are ordered)

Page 20: Computational Geometry for  the Tablet PC

Problem: Test if a point is inside a convex polygon using CCW Tests

Page 21: Computational Geometry for  the Tablet PC

Convex hull Smallest

enclosing convex figure

Rubber band “algorithm”

Page 22: Computational Geometry for  the Tablet PC

Compute the Convex Hull

Page 23: Computational Geometry for  the Tablet PC

Algorithms Convex hull algorithms: O(nlog n)

Related to sorting Insertion algorithm Gift Wrapping (Jarvis’s march) Divide and Conquer Graham Scan

Page 24: Computational Geometry for  the Tablet PC

Convex Hull AlgorithmsGift wrapping

Page 25: Computational Geometry for  the Tablet PC

Divide and Conquer

Page 26: Computational Geometry for  the Tablet PC

Graham Scan Polar sort the points around a point

inside the hull Scan points in CCW order

Discard any point that causes a CW turn

If CCW advance If !CCW, discard current point and back

up

Page 27: Computational Geometry for  the Tablet PC

Polar sort the red points around q(Start with p, CCW order)

pq

Page 28: Computational Geometry for  the Tablet PC

Graham Scan Algorithm Stack of vertices

Possible hull vertices

z – next vertex y – top of stack x – next on stack

If CCW(x, y, z) Push(x)

If (! CCW(x, y, z)) Pop stack

xy

z

zy

x

Page 29: Computational Geometry for  the Tablet PC

GS Example to walk through

Page 30: Computational Geometry for  the Tablet PC

Student submission: Give order vertices are discard in the scan

p

Page 31: Computational Geometry for  the Tablet PC

Application of Convex Hull Construct a Convex Hull Selection

Lasoo Maintain convex hull of pen stroke for

selection Operations on packet event in RTS New packet is outside of the hull

Update the hull Packet is inside the hull

Computation to make it more efficient when pen leaves the hull

Page 32: Computational Geometry for  the Tablet PC

New Packet outside the hull

Page 33: Computational Geometry for  the Tablet PC

New Packet inside the hull