CS133 Computational Geometry Computational Geometry Primitives 1 - - PowerPoint PPT Presentation

β–Ά
cs133
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CS133

Computational Geometry

Computational Geometry Primitives

1

slide-2
SLIDE 2

Point Representation

A point in the 2D Cartesian space is represented as a vector from the origin to the point π‘ž = 𝑦, 𝑧

2

p p x y O

slide-3
SLIDE 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

3

p2 p1

slide-4
SLIDE 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

slide-5
SLIDE 5

CCW Sort

What is the cross/dot product of the vectors

  • f two points?

5

slide-6
SLIDE 6

CCW Comparator

6

𝑅1 𝑅2 𝑅3 𝑅4

A point in 𝑅2 or 𝑅3 precedes a point in 𝑅4 or 𝑅1 Two points in the same half are

  • rdered based on

their angle Two points with the same angle are assumed to be equal

slide-7
SLIDE 7

CCW Comparator

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

  • 1: π‘ž1 precedes π‘ž2

+1: π‘ž2 precedes π‘ž1 0: On the same angle

slide-8
SLIDE 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

slide-9
SLIDE 9

Collinearity

Given three points, check if they are on the same straight line Collinear(π‘ž1, π‘ž2, π‘ž)

Return π‘ž1π‘ž2 Γ— π‘ž1π‘ž == 0

9

π‘ž1 π‘ž2 π‘ž π‘ž

slide-10
SLIDE 10

Missing Square Problem

10

Hint: Test the collinearity of three points on the figure

slide-11
SLIDE 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π‘ž If π‘‘π‘ž < 0

Return β€œright”

If π‘‘π‘ž > 0

Return β€œleft”

Return β€œon-the-line”

11

π‘ž1 π‘ž2 π‘ž π‘ž π‘ž

slide-12
SLIDE 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

slide-13
SLIDE 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

slide-14
SLIDE 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

slide-15
SLIDE 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 See the rest of the derivation in the notes

15

π‘ž1 π‘ž2 π‘ž3 π‘ž4 π‘ž0

slide-16
SLIDE 16

Line Segment Intersection

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

16