introduction to computational geometry hackson leung@hw311
TRANSCRIPT
![Page 1: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/1.jpg)
Introduction to Computational GeometryHackson Leung@HW311
![Page 2: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/2.jpg)
Agenda• Dot, Line and Plane
• Cartesian Coordinate System
• Straight Line and Segment
• Distance – how to measure?
• Cartesian Coordinate Geometry
• Vector Geometry
• Intersections
• Polygons
![Page 3: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/3.jpg)
DOT, LINE AND PLANETo begin with
![Page 4: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/4.jpg)
Geometry• ``Geometry (Greek γεωμετρία; geo = earth,
metria = measure) is a part of mathematics concerned with questions of size, shape, and relative position of figures and with properties of space.’’ – Wikipedia
• What to deal with?• Lines• Polygons• Planes• Objects (in N dimensional!)
![Page 5: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/5.jpg)
Geometry
![Page 6: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/6.jpg)
Simple geometry revisit• 1-Dimensional
• Simply R • a single point and line only• e.g. Number Line
• 2-Dimensional• 2-tuple (a.k.a. pair)• Can represent point, line and plane
• 3-Dimensional• 3-tuple (a.k.a. Triple)• Can represent…?
![Page 7: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/7.jpg)
Computational Geometry• Adopt algorithmic approach to solve problems
in terms of geometry• e.g. List out all possible distinct intersection points,
given several lines
• In this session, we only focus on 2-D geometry only• Further info can be found at ``Advanced
Computational Geometry’’
![Page 8: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/8.jpg)
CARTESIAN COORDINATESYSTEM
You must have learnt it in Mathematics
![Page 9: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/9.jpg)
Cartesian Coordinate System• Terminologies
• Don’t tell me that you don’t know them!y-axis
x-axis
A point with +ve x and y coordinates
![Page 10: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/10.jpg)
Cartesian Coordinate System• Terminologies
• Don’t tell me that you don’t know them!y-axis
x-axis
A straight line with negative slope, passing through origin
![Page 11: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/11.jpg)
Cartesian Coordinate System• Terminologies
• Don’t tell me that you don’t know them!y-axis
x-axis
A regular pentagon
![Page 12: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/12.jpg)
Cartesian Coordinate System
y-axis
x-axis
• You may not know this
Two straight lines intersecting at one point
![Page 13: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/13.jpg)
Cartesian Coordinate System
y-axis
x-axis
A straight line intersects the pentagon at two points
• You may not know this
![Page 14: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/14.jpg)
Cartesian Coordinate System• So how to deal with…
• Learn more and you will know
y-axis
x-axis
Two straight lines intersecting at one point
y-axis
x-axis
A straight line intersects the pentagon at two points
![Page 15: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/15.jpg)
LINE AND SEGMENTDiversify
![Page 16: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/16.jpg)
Line and Segment• Line: infinitely long
• Segment: Finite “region” within the line
• Line is a more general representation of any line segment within itself
![Page 17: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/17.jpg)
DISTANCEWay to describe how far we are
![Page 18: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/18.jpg)
Distance• Problem: Given two points, how far are they?
• Use ruler to measure…• In computer, no way!• Not precise enough!
Length l P2
(x2, y2)
P1
(x1, y1)
![Page 19: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/19.jpg)
Distance• Problem: Given two points, how far are they?
• If we do not care about the actual distance…• Think about that the world is full of grids…• And you can only walk on their sides
• The famous Manhattan Distance
Length l P2
(x2, y2)
P1
(x1, y1)
2121 yyxxl
![Page 20: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/20.jpg)
Distance• Problem: Given two points, how far are they?
• If we do care about the actual distance…• Manhattan distance gives us a brief idea to
calculate the actual distances• If you have learnt Pythagoras’s Theorem…
• Euclidean Distance Length l
P2 (x2, y2)
P1
(x1, y1)a = | x2 – x1 |
b = | y2 – y1 |
221
221 )()( yyxxl
![Page 21: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/21.jpg)
Distance• Problem: Given a line segment, how long is it?
• Treat the two ends as points• Go back to last slide
![Page 22: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/22.jpg)
Distance• Problem: Given two line segments, which one
is the longest?• Easy
• Euclidean Distance• Apply Pythagoras’s Theorem• Compare the length
• …Really that easy?
![Page 23: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/23.jpg)
Distance• Problem: Given two line segments, which one
is the longest?• Difficulties
• Length of segment A = √4 = 2• Length of segment B = 1.9999999…• In computer, it may turn out that A = B!• Known as precision error
• Cure• Use Manhattan Distance (does it work?)
• LA > LB LA2 > LB
2 when LA and LB are non-negative
![Page 24: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/24.jpg)
CARTESIAN COORDINATEGEOMETRY
x, y and z
![Page 25: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/25.jpg)
Coordinate Geometry• Basically from Cartesian Coordinate System
• How to describe:• A point?
• (x, y) Coordinates for 2D
• A line?• Straight line equation
• A line segment?• Straight line equation, plus range of x and y• Two points form a segment
![Page 26: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/26.jpg)
Coordinate Geometry• For straight line, we need to know its slope
• Given two points on the line• slope = m = change of y value / change of x value• What if x = 0?
• Common representation: point-slope form• (y-y1) = m(x-x1)
• Always possible to represent?
• Another choice: two-point form• y - y1 / x – x1 = y1 – y2 / x1 – x2
• If x1 = x2, then?
![Page 27: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/27.jpg)
VECTOR GEOMETRYArrow’s World
![Page 28: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/28.jpg)
Vector Geometry• What is a vector?
• Geometric object which has both magnitude and direction (think of line segment)
• A notation of means a motion from A to B• Notation: (x, y) means a point P from O (0, 0) to
(x, y) (Note the terminology!)y-axis
x-axis
A vector from origin to a certain point
![Page 29: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/29.jpg)
Vector Geometry• Properties
• Length of vector =
• Addition: (x1, y1) + (x2, y2) = (x3, y3)
• Subtraction: Reverse addition only
22 yx
y-axis
x-axis
(x1, y1) (x2, y2)
(x3, y3)
![Page 30: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/30.jpg)
Vector Geometry• Properties
• Multiplication• Dot Product: (x1, y1) (x‧ 2, y2) = x1*x2 - y1*y2
• Projection of (x1, y1) under (x2, y2) with product of their length
• Wedge Product: (x1, y1)^(x2, y2) = x1*y2 - y1*x2
• Dot Product on itself?• Wedge Product on itself?
![Page 31: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/31.jpg)
Vector Geometry• Straight line equation
• Describe any vectors r that end on a line u, which passes through r0=(a, b) and parallel to r1=(c, d)
• u: r = r0 + tr1 , t is any real number
![Page 32: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/32.jpg)
INTERSECTIONSWhen lines hit
![Page 33: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/33.jpg)
Intersections• Recall the previous problem
• How to find the intersection point, if any?
y-axis
x-axis
Two straight lines intersecting at one point
![Page 34: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/34.jpg)
Intersections• How to find the intersection point, if any?
• Cartesian coordinate geometry• Given K straight line equations, find all distinct
intersection point(s)• Usually a line is defined by giving two arbitrary
points which are on the line• How to represent its equation?• What if a line is a vertical line?
![Page 35: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/35.jpg)
Intersections• How to find the intersection point, if any?
• Cartesian coordinate geometry• Given 2 straight line equations, find all distinct
intersection point(s)• HKOI1998 Junior Q1 – Simultaneous Equations• How about K lines?
![Page 36: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/36.jpg)
Intersections• How to find the intersection point, if any?
• Vector geometry• Given 2 straight line equations, find all distinct
intersection point(s)• Need to find their equations?• Two vectors are formed, let them be AB and CD• We let vector itself be a line
• In general, r0 = OA, r1 = AB
![Page 37: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/37.jpg)
Intersections• How to find the intersection point, if any?
• Vector geometry• Given 2 straight line equations, find all distinct
intersection point(s)• Two vectors are formed, let them be AB and CD
CDAB
CDAC
CDAB
CDOAOCu
CDOAOCCDABu
CDOCCDABuCDOA
vuCDvOCABuOA
)(
)(
,,
![Page 38: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/38.jpg)
Intersections• How to find the intersection point, if any?
• Vector geometry
• Clearly, produces the intersection point• What if is zero?
• Parallel but not the same line• Parallel but they are on the same line
• How about the segment intersection?
CDAB
CDAC
CDAB
CDOAOCu
)(
ABuOACDAB
![Page 39: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/39.jpg)
POLYGONOptional topic
![Page 40: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/40.jpg)
Polygon• If time allows, we would discuss the following
topics• Polygon – Convex or Concave• Is a point inside or outside a polygon?• Given N points, can I find a minimum bounded
polygon that includes those points?• I have two convex polygons, tell me their
intersection area• I have two polygons, tell me if they can combine to
a single polygon through rotation and translation
![Page 41: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/41.jpg)
Practice Problems• HKOJ2071 Little Stage
• HKOJ2074 Storage Centre
• HKOJ2980 Simultaneous Equation
![Page 42: Introduction to Computational Geometry Hackson Leung@HW311](https://reader035.vdocuments.mx/reader035/viewer/2022062221/56649ec05503460f94bcb9d4/html5/thumbnails/42.jpg)
Q&A• Remember: TFT is coming!