cs133
play

CS133 Computational Geometry Computational Geometry Primitives 1 - PowerPoint PPT Presentation

CS133 Computational Geometry Computational Geometry Primitives 1 Point Representation A point in the 2D Cartesian space is represented as a vector from the origin to the point = , p p y O x 2 Line Segment Representation


  1. CS133 Computational Geometry Computational Geometry Primitives 1

  2. Point Representation A point in the 2D Cartesian space is represented as a vector from the origin to the point π‘ž = 𝑦, 𝑧 p p y O x 2

  3. Line Segment Representation A line segment is represented by its two end points Length= 𝑏 βˆ’ 𝑐 Straight lines are usually represented by two points on it p1 p2 3

  4. Application: CCW sort How to sort a list of points in a CCW order around the origin? NaΓ―ve solution: Calculate all the angles and sort Advantages: Easy and can reuse an existing sort algorithm as-is Disadvantages: arctan calculation is complex and might be inaccurate 4

  5. CCW Sort What is the cross/dot product of the vectors of two points? 5

  6. CCW Comparator 𝑅 2 𝑅 1 A point in 𝑅 2 or 𝑅 3 precedes a point in 𝑅 4 or 𝑅 1 Two points in the Two points with same half are the same angle ordered based on are assumed to their angle be equal 𝑅 3 𝑅 4 6

  7. -1: π‘ž 1 precedes π‘ž 2 CCW Comparator +1: π‘ž 2 precedes π‘ž 1 0: On the same angle compare( π‘ž 1 = 𝑦 1 , 𝑧 1 , π‘ž 2 = (𝑦 2 , 𝑧 2 ) ) If ( 𝑦 1 < 0 and 𝑦 2 > 0 ) OR ( 𝑦 1 > 0 and 𝑦 2 < 0 ) Return 𝑦 1 < 0 ? -1 : +1 cp = π‘ž 1 Γ— π‘ž 2 If π‘‘π‘ž < 0 Return -1 If π‘‘π‘ž > 0 Return +1 // cp = 0 If ( 𝑧1 < 0 and 𝑧 2 > 0 ) OR ( 𝑧1 > 0 and 𝑧2 < 0 ) Return 𝑧 1 < 0 ?-1 : +1 Return 0 7

  8. CCW Sort How to sort a set of points around their geometric center? First, compute the geometric center Then, translate the points to make the origin at the center 8

  9. Collinearity Given three points, check if they are on the same straight line π‘ž 2 Collinear( π‘ž 1 , π‘ž 2 , π‘ž ) Return π‘ž 1 π‘ž 2 Γ— π‘ž 1 π‘ž == 0 π‘ž π‘ž π‘ž 1 9

  10. Missing Square Problem Hint: Test the collinearity of three points on the figure 10

  11. Direction Given a straight line (ray) and a point, find whether the point is to the right or left of the line π‘ž Direction( π‘ž 1 , π‘ž 2 , π‘ž ) π‘‘π‘ž = π‘ž 1 π‘ž 2 Γ— π‘ž 1 π‘ž π‘ž 2 π‘ž If π‘‘π‘ž < 0 Return β€œright” π‘ž π‘ž 1 If π‘‘π‘ž > 0 Return β€œleft” Return β€œon -the- line” 11

  12. Point-line Relationship Given a line segment and a point, find whether the point is on the line segment or not Coincident( π‘ž 1 (𝑦 1 , 𝑧 1 ) , π‘ž 2 (𝑦 2 , 𝑧 2 ) , π‘ž(𝑦, 𝑧) ) If NOT Collinear( π‘ž 1 , π‘ž 2 , π‘ž ) Return false Return 𝑦 ∈ min 𝑦 1 , 𝑦 2 , max 𝑦 1 , 𝑦 2 AND ( 𝑧 ∈ min 𝑧 1 , 𝑧 2 , max 𝑧 1 , 𝑧 2 12

  13. Line-line Relationship Given two straight lines, find whether they intersect or not IsIntersected( π‘ž 1 , π‘ž 2 , π‘ž 3 , π‘ž 4 ) If π‘ž 1 π‘ž 2 Γ— π‘ž 3 π‘ž 4 β‰  0 Return true // intersected in a point // The two lines are parallel If Collinear( π‘ž 1 , π‘ž 2 , π‘ž 3 ) Return true // Lines are coincident Return false // Parallel ant not coincident 13

  14. Line-line Intersection Given two straight lines, find their intersection Solve the two linear equations that represent the two lines One solution βž” The lines intersect in a point Infinite solutions βž” The lines are coincident No solutions βž” The lines are disjoint parallel 14

  15. Line-line Intersection π‘ž 1 , π‘ž 2 : First line (input) π‘ž 3 , π‘ž 4 : Second line (input) π‘ž 0 : Intersection point (output) π‘ž 0 must be collinear with π‘ž 1 π‘ž 2 and π‘ž 3 π‘ž 4 π‘ž 1 π‘ž 2 Γ— π‘ž 1 π‘ž 0 = 0 π‘ž 3 π‘ž 4 Γ— π‘ž 3 π‘ž 0 = 0 π‘ž 2 π‘ž 3 π‘ž 0 See the rest of the π‘ž 4 derivation in the notes π‘ž 1 15

  16. Line Segment Intersection Given two line segments, find whether they intersect or not. If they intersect, find their intersection point (Homework) 16

Recommend


More recommend