Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat...
Transcript of Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat...
![Page 1: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/1.jpg)
Rodrigo Silveira
Computational Geometry
Facultat d’Informatica de Barcelona
Universitat Politecnica de Catalunya
Basic tools:orientation tests
![Page 2: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/2.jpg)
Turning right or turning left?
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Consider a sequence of 3 points: p,q, r
pq
r
![Page 3: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/3.jpg)
Turning right or turning left?
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Basic question: do they make a right turn?A left turn?Or perhaps they are colinear?
Consider a sequence of 3 points: p,q, r
pq
r
![Page 4: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/4.jpg)
Turning right or turning left?
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Basic question: do they make a right turn?A left turn?Or perhaps they are colinear?
Consider a sequence of 3 points: p,q, r
pq
r
![Page 5: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/5.jpg)
Turning right or turning left?
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Basic question: do they make a right turn?A left turn?Or perhaps they are colinear?
Consider a sequence of 3 points: p,q, r
pq
r
![Page 6: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/6.jpg)
Turning right or turning left?
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Basic question: do they make a right turn?A left turn?Or perhaps they are colinear?
Consider a sequence of 3 points: p,q, r
pq
r
This is a fundamental basic operation in geometric algorithms. Requires a solution that is
• Efficient
• Numerically robust
![Page 7: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/7.jpg)
Turning right or turning left?
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Basic question: do they make a right turn?A left turn?Or perhaps they are colinear?
Consider a sequence of 3 points: p,q, r
pq
r
This is a fundamental basic operation in geometric algorithms. Requires a solution that is
• Efficient
• Numerically robust
Solution: signed area of triangle 4pqr
![Page 8: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/8.jpg)
Signed area of triangle
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
The signed area of 4pqr tells us the area ofthe triangle, and the sign gives the orientation(left-turning or right-turning)
Signed area of 4pqr
pq
r
• Can the area be zero?
![Page 9: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/9.jpg)
Signed area of triangle
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
The signed area of 4pqr tells us the area ofthe triangle, and the sign gives the orientation(left-turning or right-turning)
Signed area of 4pqr
pq
r
• A(4pqr) is twice the area of the parallelogramdefined by vectors pq and w
• Recall: in 2-dimensions, the area of the paral-lelogram defined by two vectors is the deter-minant of a 2 × 2 matrix whose columns arethe two vectors
• Can the area be zero?
Computing A(4pqr)
pq
rw = r − p
pq = q − p
![Page 10: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/10.jpg)
Signed area of triangle
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Signed area of 4pqr
A(4pqr) =1
2
∣∣∣∣∣ pqx wx
pqy wy
∣∣∣∣∣
p
q
rw = r − p
pq = q − p
![Page 11: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/11.jpg)
Signed area of triangle
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Signed area of 4pqr
A(4pqr) =1
2
∣∣∣∣∣ pqx wx
pqy wy
∣∣∣∣∣
p
q
rw = r − p
pq = q − p
=1
2
∣∣∣∣∣ (q − p)x (r − p)x
(q − p)y (r − p)y
∣∣∣∣∣=
1
2
∣∣∣∣∣ qx − px rx − px
qy − py ry − py
∣∣∣∣∣=
1
2
∣∣∣∣∣∣∣∣px qx rx
py qy ry
1 1 1
∣∣∣∣∣∣∣∣
![Page 12: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/12.jpg)
Signed area of triangle
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Signed area of 4pqr
A(4pqr) =1
2
∣∣∣∣∣ pqx wx
pqy wy
∣∣∣∣∣
p
q
rw = r − p
pq = q − p
=1
2
∣∣∣∣∣ (q − p)x (r − p)x
(q − p)y (r − p)y
∣∣∣∣∣=
1
2
∣∣∣∣∣ qx − px rx − px
qy − py ry − py
∣∣∣∣∣=
1
2
∣∣∣∣∣∣∣∣px qx rx
py qy ry
1 1 1
∣∣∣∣∣∣∣∣Fact: (check it yourself!)
A(4pqr) > 0 if and only if p, q, r are in counter-clockwise order
Does it turn right or left?
![Page 13: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/13.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Is point r to the right or left of the oriented line `?
Point with respect to a line
r
p
q
`
RIGHT
LEFT
![Page 14: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/14.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Is point r to the right or left of the oriented line `?
Point with respect to a line
r
p
q
`
Equivalent question: do p, q, r turn right or left?
RIGHT
LEFT
![Page 15: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/15.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Is point r to the right or left of the oriented line `?
Point with respect to a line
r
p
q
`
Line-segment intersection test
Equivalent question: do p, q, r turn right or left?
`
pq
r
sDoes segment rs intersect line `?
RIGHT
LEFT
RIGHT
LEFT
![Page 16: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/16.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Is point r to the right or left of the oriented line `?
Point with respect to a line
r
p
q
`
Line-segment intersection test
Equivalent question: do p, q, r turn right or left?
`
pq
r
sDoes segment rs intersect line `?
rs intersects line ` ↔ r and s are on opposite sides of `
RIGHT
LEFT
RIGHT
LEFT
↔ (r is to the left and s is to the right of `) OR (r is to the right and s is to the left of `)
rs intersects line ` ↔ r and s are on opposite sides of `
![Page 17: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/17.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Does segment rs intersect halfline h?
Halfline-segment intersection
r
p
h
RIGHT
LEFT
q
s
![Page 18: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/18.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Does segment rs intersect halfline h?
Halfline-segment intersection
r
p
h
Equivalent question(s):
• r and s are on opposite sides of h(so we can assume r is to the left of h)
RIGHT
LEFT
q
s
![Page 19: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/19.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Does segment rs intersect halfline h?
Halfline-segment intersection
r
p
h
Equivalent question(s):
• r and s are on opposite sides of h(so we can assume r is to the left of h)
RIGHT
LEFT
q
s
hr
s
p
RIGHTLEFT
q
![Page 20: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/20.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Does segment rs intersect halfline h?
Halfline-segment intersection
r
p
h
Equivalent question(s):
• r and s are on opposite sides of h(so we can assume r is to the left of h)
RIGHT
LEFT
q
s
hr
s
p
RIGHTLEFT
qp h
q
r
sRIGHTLEFT
ph
q
r
sRIGHTLEFT
![Page 21: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/21.jpg)
More things you can do with this test
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
Does segment rs intersect halfline h?
Halfline-segment intersection
r
p
h
Equivalent question(s):
• r and s are on opposite sides of h(so we can assume r is to the left of h)
RIGHT
LEFT
q
s
• r, s, p makes a right turn
hr
s
p
RIGHTLEFT
qp h
q
r
sRIGHTLEFT
ph
q
r
sRIGHTLEFT
![Page 22: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/22.jpg)
More things you can do with this test
Does segment pq intersect segment rs?
Segment-segment intersection
r
p
q
s
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
![Page 23: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/23.jpg)
More things you can do with this test
Does segment pq intersect segment rs?
Segment-segment intersection
r
p
q
s
r
p
q
s
Computational Geometry, Facultat d’Informatica de Barcelona, UPC
![Page 24: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/24.jpg)
More things you can do with this test
Does segment pq intersect segment rs?
Segment-segment intersection
r
p
Equivalent question(s):
• r and s are on opposite “sides” of pq
q
s
r
p
q
s
Computational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPC
![Page 25: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/25.jpg)
More things you can do with this test
Does segment pq intersect segment rs?
Segment-segment intersection
r
p
Equivalent question(s):
• r and s are on opposite “sides” of pq
q
s
r
p
q
s
Computational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPC
![Page 26: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/26.jpg)
More things you can do with this test
Does segment pq intersect segment rs?
Segment-segment intersection
r
p
Equivalent question(s):
• r and s are on opposite “sides” of pq
q
s
• p and q are on opposite “sides” of rs
r
p
q
s
Computational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPC
![Page 27: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/27.jpg)
Summary
Computational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPC
Things we can do with the orientation test• Test if p, q, r make a right turn
• Test if a point is to the left of a line
• Test if a segment and a line intersect
• Test if a segment and a halfline intersect
• Test if two segments intersect
• Test if a point is inside a triangle
All by evaluating the sign of a couple of determinants!
![Page 28: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/28.jpg)
Summary
Computational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPC
Things we can do with the orientation test• Test if p, q, r make a right turn
• Test if a point is to the left of a line
• Test if a segment and a line intersect
• Test if a segment and a halfline intersect
• Test if two segments intersect
• Test if a point is inside a triangle
All by evaluating the sign of a couple of determinants!
Another useful test: point in circle• See notes on course webpage
![Page 29: Universitat Polit ecnica de Catalunya Facultat d’Inform ... · Computational Geometry, Facultat d’Inform atica de Barcelona, UPC Things we can do with the orientation test Test](https://reader036.fdocuments.net/reader036/viewer/2022071109/5fe4617f1bc0e62ee4573647/html5/thumbnails/29.jpg)
Summary
Computational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPCComputational Geometry, Facultat d’Informatica de Barcelona, UPC
Things we can do with the orientation test• Test if p, q, r make a right turn
• Test if a point is to the left of a line
• Test if a segment and a line intersect
• Test if a segment and a halfline intersect
• Test if two segments intersect
• Test if a point is inside a triangle
All by evaluating the sign of a couple of determinants!
Questions?
Another useful test: point in circle• See notes on course webpage