1 / 152

Geometry Introduction

Geometry Introduction. Topic. Introduction Two lines Intersection Test Point inside polygon Convex hull Line Segments Intersection Algorithm. Geometry. Components Scalar (S) Point (P) Free vector (V). Allowed operations S * V  V V + V  V P – P  V P + V  P.

cuyler
Download Presentation

Geometry Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Geometry Introduction

  2. Topic • Introduction • Two lines Intersection Test • Point inside polygon • Convex hull • Line Segments Intersection Algorithm

  3. Geometry Components • Scalar (S) • Point (P) • Free vector (V) • Allowed operations • S * V  V • V + V  V • P – P  V • P + V  P

  4. Examples u+v Vector addition v u p p-q Point subtraction q p+v v Point-vector addition p

  5. a = 0.5 a = 1.25 q p จุดใดๆบนเส้นตรงที่ลากผ่านจุด p และ q สามารถสร้างได้จาก affine combination:

  6. Euclidean Geometry • In affine geometry, angle and distance are not defined. • Euclidean geometry is an extension providing an additional operation called “inner product” • There are other types of geometry that extends affine geometry such as projective geometry, hyperbolic geometry…

  7. Dot product is a mapping from two vectors to a real number. Dot product Distance Length Angle Orthogonality: u and v are orthogonal when

  8. Topic • Introduction • Two lines Intersection Test • Point inside polygon • Convex hull • Line Segments Intersection Algorithm

  9. p2 p3 p3 p2 p4 p1 p2 p1 p0 p1 (2) (3) Cross-Product-Based Geometric Primitives Some fundamental geometric questions: source: 91.503 textbook Cormen et al. (1)

  10. p2 p1 p0 (1) Cross-Product-Based Geometric Primitives: (1) 33.1 Advantage: less sensitive to accumulated round-off error source: 91.503 textbook Cormen et al.

  11. p2 p1 p0 (2) Cross-Product-Based Geometric Primitives: (2) 33.2 source: 91.503 textbook Cormen et al.

  12. isLeft() // isLeft(): tests if a point is Left|On|Right of an infinite line.//    Input:  three points P0, P1, and P2//    Return: >0 for P2 left of the line through P0 and P1//            =0 for P2 on the line//            <0 for P2 right of the lineinline intisLeft( Point P0, Point P1, Point P2 ){    return ( (P1.x - P0.x) * (P2.y - P0.y)            - (P2.x - P0.x) * (P1.y - P0.y) );}

  13. Segment-Segment Intersection • Finding the actual intersection point • Approach: parametric vs. slope/intercept • parametric generalizes to more complex intersections • e.g. segment/triangle • Parameterize each segment Lab c Lcd C=d-c b Lab c q(t)=c+tC Lcd b d A=b-a a d a p(s)=a+sA Intersection: values of s, t such that p(s) =q(t) : a+sA=c+tC 2 equations in unknowns s, t : 1 for x, 1 for y source: O’Rourke, Computational Geometry in C

  14. Assume that a = (x1,y1) b = (x2,y2) c = (x3,y3) d = (x4,y4)

  15. Code typedefstruct point { double x; double y;} point; typedefstruct line { point p1; point p2;} line; intcheck_lines(line *line1, line *line2, point *hitp) { double d = (line2->p2.y - line2->p1.y)*(line1->p2.x-line1->p1.x) - (line2->p2.x - line2->p1.x)*(line1->p2.y-line1->p1.y); double ns = (line2->p2.x - line2->p1.x)*(line1->p1.y-line2->p1.y) - (line2->p2.y - line2->p1.y)*(line1->p1.x-line2->p1.x); double nt = (line1->p2.x - line1->p1.x)*(line1->p1.y - line2->p1.y) - (line1->p2.y - line1->p1.y)*(line1->p1.x - line2->p1.x); if(d == 0) return 0; double s= ns/d; double t = nt/d; return (s >=0 && s <= 1 && t >= 0 && t <= 1)); }

  16. p3 p2 p4 p1 (3) Intersection of 2 Line Segments Step 1: Bounding Box Test p3 and p4 on opposite sides of p1p2 33.3 Step 2: Does each segment straddle the line containing the other? source: 91.503 textbook Cormen et al.

  17. Topic • Introduction • Two lines Intersection Test • Point inside polygon • Convex hull • Line Segments Intersection Algorithm

  18. Point Inside Polygon Test • Given a point, determine if it lies inside a polygon or not

  19. Ray Test • Fire ray from point • Count intersections • Odd = inside polygon • Even = outside polygon

  20. Problems With Rays • Fire ray from point • Count intersections • Odd = inside polygon • Even = outside polygon • Problems • Ray through vertex

  21. Problems With Rays • Fire ray from point • Count intersections • Odd = inside polygon • Even = outside polygon • Problems • Ray through vertex

  22. Problems With Rays • Fire ray from point • Count intersections • Odd = inside polygon • Even = outside polygon • Problems • Ray through vertex • Ray parallel to edge

  23. Solution • Edge Crossing Rule • an upward edge includes its starting endpoint, and excludes its final endpoint; • a downward edge excludes its starting endpoint, and includes its final endpoint; • horizontal edges are excluded; and • the edge-ray intersection point must be strictly right of the point P. • Use horizontal ray for simplicity in computation

  24. Code //cn_PnPoly(): crossing number test for a point in a polygon//      Input:   P = a point,//               V[] = vertex points of a polygon V[n+1] with V[n]=V[0]//      Return:  0 = outside, 1 = inside// This code is patterned after [Franklin, 2000]intcn_PnPoly( Point P, Point* V, int n ){intcn = 0;    // the crossing number counter    // loop through all edges of the polygon    for (inti=0; i<n; i++) {    // edge from V[i] to V[i+1]       if (((V[i].y <= P.y) && (V[i+1].y > P.y))    // an upward crossing        || ((V[i].y > P.y) && (V[i+1].y <= P.y))) { // a downward crossing            // compute the actual edge-ray intersect x-coordinate            float vt = (float)(P.y - V[i].y) / (V[i+1].y - V[i].y);            if (P.x < V[i].x + vt * (V[i+1].x - V[i].x)) // P.x < intersect                ++cn;   // a valid crossing of y=P.y right of P.x        }    }    return (cn&1);    // 0 if even (out), and 1 if odd (in)}

  25. A Better Way

  26. A Better Way

  27. A Better Way

  28. A Better Way

  29. A Better Way

  30. A Better Way

  31. A Better Way

  32. A Better Way

  33. A Better Way

  34. A Better Way

  35. A Better Way

  36. A Better Way • One winding = inside

  37. A Better Way

  38. A Better Way

  39. A Better Way

  40. A Better Way

  41. A Better Way

  42. A Better Way

  43. A Better Way

  44. A Better Way

  45. A Better Way

  46. A Better Way

  47. A Better Way

  48. A Better Way • zero winding = outside

  49. Requirements • Oriented edges • Edges can be processed in any order

  50. Advantages • Extends to 3D! • Numerically stable • Even works on models with holes: • Odd k: inside • Even k: outside • No ray casting

More Related