Here are my slides in some basic algorithms in Computational Geometry:
1.- Line Intersection
2.- Sweeping Line
3.- Convex Hull
They are the classic one, but there is still a lot for anybody wanting to get in computer graphics to study. I recomend
Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars. 2008. Computational Geometry: Algorithms and Applications (3rd ed. ed.). TELOS, Santa Clara, CA, USA.
Presentation of the paper "An output-sensitive algorithm for computing (projections of) resultant polytopes" in the Annual Symposium on Computational Geometry (SoCG 2012)
A Formal Model and an Algorithm for Generating the Permutations of a MultisetVincenzo De Florio
This paper may be considered as a mathematical divertissement as well as a didactical tool for
undergraduate students in a universitary course on algorithms and computation. The well-known problem of
generating the permutations of a multiset of marks is considered. We define a formal model and an abstract
machine (an extended Turing machine). Then we write an algorithm to compute on that machine the successor
of a given permutation in the lexicographically ordered set of permutations of a multiset. Within the model we
analyze the algorithm, prove its correctness, and show that the algorithm solves the above problem. Then we
describe a slight modification of the algorithm and we analyze in which cases it may result in an improvement of
execution times.
This paper, the ideas in it, and its realization are the work of the first author only.
Presentation of the paper "An output-sensitive algorithm for computing (projections of) resultant polytopes" in the Annual Symposium on Computational Geometry (SoCG 2012)
A Formal Model and an Algorithm for Generating the Permutations of a MultisetVincenzo De Florio
This paper may be considered as a mathematical divertissement as well as a didactical tool for
undergraduate students in a universitary course on algorithms and computation. The well-known problem of
generating the permutations of a multiset of marks is considered. We define a formal model and an abstract
machine (an extended Turing machine). Then we write an algorithm to compute on that machine the successor
of a given permutation in the lexicographically ordered set of permutations of a multiset. Within the model we
analyze the algorithm, prove its correctness, and show that the algorithm solves the above problem. Then we
describe a slight modification of the algorithm and we analyze in which cases it may result in an improvement of
execution times.
This paper, the ideas in it, and its realization are the work of the first author only.
Summarize for Discrete mathematics (math 521) and it's especially students of graduate studies of the Institute of Statistical Studies and Research - Cairo University
3. Linear Algebra for Machine Learning: Factorization and Linear TransformationsCeni Babaoglu, PhD
The seminar series will focus on the mathematical background needed for machine learning. The first set of the seminars will be on "Linear Algebra for Machine Learning". Here are the slides of the third part which is discussing factorization and linear transformations.
Here is the link of the first part which was discussing linear systems: https://www.slideshare.net/CeniBabaogluPhDinMat/linear-algebra-for-machine-learning-linear-systems/1
Here are the slides of the second part which was discussing basis and dimension:
https://www.slideshare.net/CeniBabaogluPhDinMat/2-linear-algebra-for-machine-learning-basis-and-dimension
Its states Periodic function, Fourier series for disontinous function, Fourier series, Intervals, Odd and even functions, Half range fourier series etc. Mostly used as active learning assignment in Degree 3rd sem students.
The introduction to my class on machine learning. The subjects covered in this class go from:
1.- Linear Classifiers
2.- Non Linear Classifiers
3.- Graphical Models
4.- Clustering
5.- Etc
I am planning to upload the rest once I feel they are at the level.
Summarize for Discrete mathematics (math 521) and it's especially students of graduate studies of the Institute of Statistical Studies and Research - Cairo University
3. Linear Algebra for Machine Learning: Factorization and Linear TransformationsCeni Babaoglu, PhD
The seminar series will focus on the mathematical background needed for machine learning. The first set of the seminars will be on "Linear Algebra for Machine Learning". Here are the slides of the third part which is discussing factorization and linear transformations.
Here is the link of the first part which was discussing linear systems: https://www.slideshare.net/CeniBabaogluPhDinMat/linear-algebra-for-machine-learning-linear-systems/1
Here are the slides of the second part which was discussing basis and dimension:
https://www.slideshare.net/CeniBabaogluPhDinMat/2-linear-algebra-for-machine-learning-basis-and-dimension
Its states Periodic function, Fourier series for disontinous function, Fourier series, Intervals, Odd and even functions, Half range fourier series etc. Mostly used as active learning assignment in Degree 3rd sem students.
The introduction to my class on machine learning. The subjects covered in this class go from:
1.- Linear Classifiers
2.- Non Linear Classifiers
3.- Graphical Models
4.- Clustering
5.- Etc
I am planning to upload the rest once I feel they are at the level.
Here are my slides for my preparation class for possible students in the Master in Electrical Engineering and Computer Science (Specialization in Computer Science)... for the entrance examination here at Cinvestav GDL.
Here is the basic introduction to the probability used in my Analysis of Algorithms course at the Cinvestav Guadalajara. They go from the basic axioms to the Expected Value and Variance.
In most of the algorithms analyzed until now, we have been looking and studying problems solvable in polynomial time. The polynomial time algorithm class P are algorithms that on inputs of size n have a worst case running time of O(n^k) for some constant k. Thus, informally, we can say that the Non-Polynomial (NP) time algorithms are the ones that cannot be solved in O(n^k) for any constant k
.
Here are my slides for my preparation class for possible Master students in Electrical Engineering and Computer Science (Specialization in Computer Science)... for the entrance examination here at Cinvestav GDL.
Here are my slides for my preparation class for possible students for the Master in Electrical Engineering and Computer Science (Specialization in Computer Science)... for the entrance examination here at Cinvestav GDL.
Here, we look at the problem of going from a source s to a possible multiple destinations. At them, each of the Lemmas, Theorems and Corollaries used to prove the properties of the
1. Bellman-Ford
2. Dijkstra
are examined in detail.
Combining Models - In this slides, we look at a way to combine the answers form various weak classifiers to build a robust classifier. At the slides we look at the following subjects:
1.- Model Combination Vs Bayesian Model
2.- Bootstrap Data Sets
And the cherry on the top the AdaBoost
The Lian-Barsky algorithm is a line clipping algorithm. This algorithm is more efficient than Cohen–Sutherland line clipping algorithm and can be extended to 3-Dimensional clipping. This algorithm is considered to be the faster parametric line-clipping algorithm. The following concepts are used in this clipping:
The parametric equation of the line.
The inequalities describing the range of the clipping window which is used to determine the intersections between the line and the clip window.
Mathematics (from Greek μάθημα máthēma, “knowledge, study, learning”) is the study of topics such as quantity (numbers), structure, space, and change. There is a range of views among mathematicians and philosophers as to the exact scope and definition of mathematics
Senior data scientist and founder of the company Intelligentia Data I+D SA de CV. We are offering consultancy services, development of projects and products in Machine Learning, Big Data, Data Sciences and Artificial Intelligence.
My first set of slides (The NN and DL class I am preparing for the fall)... I included the problem of Vanishing Gradient and the need to have ReLu (Mentioning btw the saturation problem inherited from Hebbian Learning)
It has been almost 62 years since the invention of the term Artificial Intelligence by Samuel and Minsky et al. at the Dartmouth workshop College in 1956 (“Dartmouth Summer Research Project on Artificial Intelligence”) where this new area of Computer Science was invented. However, the history of Artificial Intelligence goes back to previous millennia, when the Greeks in their Myths spoke about golden robots at Hephaestus, and the Galatea of Pygmalion. They were the first automatons known at the dawn of history, and although these first attempts were only myths, automatons were invented and built through multiple civilizations in history. Nevertheless, these automatons resembled in quite limited way their final objectives, representing animals and humans. In spite of that, the greatest illusion of an automaton, the Turk by Wolfgang von Kempelen, inspired many people, trough its exhibitions, as Alexander Graham Bell and Charles Babbage to develop inventions that would change forever human history. Thus, the importance of the concept “Artificial Intelligence” as a driver of our technological dreams. And although Artificial Intelligence has never been defined in a precise practical way, the amount of research and methods that have been developed to tackle some of its basics tasks have been and are quite humongous. Thus, the importance of having an introduction to the concepts of Artificial Intelligence, thus the dream can continue.
A review of one of the most popular methods of clustering, a part of what is know as unsupervised learning, K-Means. Here, we go from the basic heuristic used to solve the NP-Hard problem to an approximation algorithm K-Centers. Additionally, we look at variations coming from the Fuzzy Set ideas. In the future, we will add more about On-Line algorithms in the line of Stochastic Gradient Ideas...
Here a Review of the Combination of Machine Learning models from Bayesian Averaging, Committees to Boosting... Specifically An statistical analysis of Boosting is done
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
This paper addresses the vulnerability of deep learning models, particularly convolutional neural networks
(CNN)s, to adversarial attacks and presents a proactive training technique designed to counter them. We
introduce a novel volumization algorithm, which transforms 2D images into 3D volumetric representations.
When combined with 3D convolution and deep curriculum learning optimization (CLO), itsignificantly improves
the immunity of models against localized universal attacks by up to 40%. We evaluate our proposed approach
using contemporary CNN architectures and the modified Canadian Institute for Advanced Research (CIFAR-10
and CIFAR-100) and ImageNet Large Scale Visual Recognition Challenge (ILSVRC12) datasets, showcasing
accuracy improvements over previous techniques. The results indicate that the combination of the volumetric
input and curriculum learning holds significant promise for mitigating adversarial attacks without necessitating
adversary training.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
2. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
2 / 88
3. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
3 / 88
5. Field of Application
VLSI design - Generation for Fast Voronoi Diagrams for Massive
Layouts Under Strict Distances to avoid Tunneling Effects!!
5 / 88
9. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
9 / 88
10. The Plane Representation
Although 3D algorithms exist...
We will deal only with algorithms working in the plane.
Object Representation
Each object is a set of points {p1, p2, ..., pn} where
pi = (xi, yi) and xi, yi ∈ R.
Example
For example an n-vertex polygon P is the following order sequence:
p0, p2, ..., pn
10 / 88
11. The Plane Representation
Although 3D algorithms exist...
We will deal only with algorithms working in the plane.
Object Representation
Each object is a set of points {p1, p2, ..., pn} where
pi = (xi, yi) and xi, yi ∈ R.
Example
For example an n-vertex polygon P is the following order sequence:
p0, p2, ..., pn
10 / 88
12. The Plane Representation
Although 3D algorithms exist...
We will deal only with algorithms working in the plane.
Object Representation
Each object is a set of points {p1, p2, ..., pn} where
pi = (xi, yi) and xi, yi ∈ R.
Example
For example an n-vertex polygon P is the following order sequence:
p0, p2, ..., pn
10 / 88
13. The Plane Representation
Although 3D algorithms exist...
We will deal only with algorithms working in the plane.
Object Representation
Each object is a set of points {p1, p2, ..., pn} where
pi = (xi, yi) and xi, yi ∈ R.
Example
For example an n-vertex polygon P is the following order sequence:
p0, p2, ..., pn
10 / 88
14. The Plane Representation
Although 3D algorithms exist...
We will deal only with algorithms working in the plane.
Object Representation
Each object is a set of points {p1, p2, ..., pn} where
pi = (xi, yi) and xi, yi ∈ R.
Example
For example an n-vertex polygon P is the following order sequence:
p0, p2, ..., pn
10 / 88
16. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
12 / 88
17. Line-segment Properties
A convex combination
Given two distinct points p1 = (x1, y1)T
and p2 = (x2, y2)T
, a convex
combination of {p1, p2} is any point p3 such that:
p3 = αp1 + (1 − α) p2 with 0 ≤ α ≤ 1.
Line Segment as Convex Combination
Given two points p1 and p2 (Known as End Points), the line segment
p1p2 is the set of convex combinations of p1 and p2.
Directed Segment
Here, we care about the direction with initial point p1 for the directed
segment −−→p1p2:
If p1 = (0, 0) then −−→p1p2 is the vector p2.
13 / 88
18. Line-segment Properties
A convex combination
Given two distinct points p1 = (x1, y1)T
and p2 = (x2, y2)T
, a convex
combination of {p1, p2} is any point p3 such that:
p3 = αp1 + (1 − α) p2 with 0 ≤ α ≤ 1.
Line Segment as Convex Combination
Given two points p1 and p2 (Known as End Points), the line segment
p1p2 is the set of convex combinations of p1 and p2.
Directed Segment
Here, we care about the direction with initial point p1 for the directed
segment −−→p1p2:
If p1 = (0, 0) then −−→p1p2 is the vector p2.
13 / 88
19. Line-segment Properties
A convex combination
Given two distinct points p1 = (x1, y1)T
and p2 = (x2, y2)T
, a convex
combination of {p1, p2} is any point p3 such that:
p3 = αp1 + (1 − α) p2 with 0 ≤ α ≤ 1.
Line Segment as Convex Combination
Given two points p1 and p2 (Known as End Points), the line segment
p1p2 is the set of convex combinations of p1 and p2.
Directed Segment
Here, we care about the direction with initial point p1 for the directed
segment −−→p1p2:
If p1 = (0, 0) then −−→p1p2 is the vector p2.
13 / 88
20. Line-segment Properties
A convex combination
Given two distinct points p1 = (x1, y1)T
and p2 = (x2, y2)T
, a convex
combination of {p1, p2} is any point p3 such that:
p3 = αp1 + (1 − α) p2 with 0 ≤ α ≤ 1.
Line Segment as Convex Combination
Given two points p1 and p2 (Known as End Points), the line segment
p1p2 is the set of convex combinations of p1 and p2.
Directed Segment
Here, we care about the direction with initial point p1 for the directed
segment −−→p1p2:
If p1 = (0, 0) then −−→p1p2 is the vector p2.
13 / 88
21. Line-segment Properties
A convex combination
Given two distinct points p1 = (x1, y1)T
and p2 = (x2, y2)T
, a convex
combination of {p1, p2} is any point p3 such that:
p3 = αp1 + (1 − α) p2 with 0 ≤ α ≤ 1.
Line Segment as Convex Combination
Given two points p1 and p2 (Known as End Points), the line segment
p1p2 is the set of convex combinations of p1 and p2.
Directed Segment
Here, we care about the direction with initial point p1 for the directed
segment −−→p1p2:
If p1 = (0, 0) then −−→p1p2 is the vector p2.
13 / 88
22. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
14 / 88
23. Cross Product
Question!!!
Given two directed segments −−→p0p1 and −−→p0p2,
Is −−→p0p1 clockwise from −−→p0p2 with respect to their common endpoint p0?
Cross Product
Cross product p1 × p2 as the signed area of the parallelogram formed
by
15 / 88
24. Cross Product
Question!!!
Given two directed segments −−→p0p1 and −−→p0p2,
Is −−→p0p1 clockwise from −−→p0p2 with respect to their common endpoint p0?
Cross Product
Cross product p1 × p2 as the signed area of the parallelogram formed
by
15 / 88
25. Cross Product
Question!!!
Given two directed segments −−→p0p1 and −−→p0p2,
Is −−→p0p1 clockwise from −−→p0p2 with respect to their common endpoint p0?
Cross Product
Cross product p1 × p2 as the signed area of the parallelogram formed
by
15 / 88
26. Cross Product
A shorter representation
p1 × p2 = det p1 p2 =det
x1 x2
y1 y2
= x1y2 − x2y1 = −p2 × p1
Thus
if p1 × p2 is positive, then p1 is clockwise from p2.
if p1 × p2 is negative, then p1 is counterclockwise from p2.
16 / 88
27. Cross Product
A shorter representation
p1 × p2 = det p1 p2 =det
x1 x2
y1 y2
= x1y2 − x2y1 = −p2 × p1
Thus
if p1 × p2 is positive, then p1 is clockwise from p2.
if p1 × p2 is negative, then p1 is counterclockwise from p2.
16 / 88
28. Cross Product
A shorter representation
p1 × p2 = det p1 p2 =det
x1 x2
y1 y2
= x1y2 − x2y1 = −p2 × p1
Thus
if p1 × p2 is positive, then p1 is clockwise from p2.
if p1 × p2 is negative, then p1 is counterclockwise from p2.
16 / 88
30. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
18 / 88
31. Turn Left or Right
Question
Given two line segments −−→p0p1 and −−→p1p2,
if we traverse −−→p0p1 and then −−→p1p2, do we make a left turn at point p1?
19 / 88
32. Turn Left or Right
Simply use the following idea
Compute cross product (p2 − p0) × (p1 − p0)!!!
This translates p0 to the origin!!!
What about (p2 − p0) × (p1 − p0) = 0?
Left Turn = counterclockwise; Right Turn = clockwise
20 / 88
33. Turn Left or Right
Simply use the following idea
Compute cross product (p2 − p0) × (p1 − p0)!!!
This translates p0 to the origin!!!
What about (p2 − p0) × (p1 − p0) = 0?
Left Turn = counterclockwise; Right Turn = clockwise
20 / 88
34. Turn Left or Right
Simply use the following idea
Compute cross product (p2 − p0) × (p1 − p0)!!!
This translates p0 to the origin!!!
What about (p2 − p0) × (p1 − p0) = 0?
Left Turn = counterclockwise; Right Turn = clockwise
20 / 88
35. Turn Left or Right
Simply use the following idea
Compute cross product (p2 − p0) × (p1 − p0)!!!
This translates p0 to the origin!!!
What about (p2 − p0) × (p1 − p0) = 0?
Left Turn = counterclockwise; Right Turn = clockwise
counterclockwise clockwise
20 / 88
36. Code for this
We have the following code
Direction(pi, pj, pk)
1 return (pk − pi) × (pj − pi)
21 / 88
37. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
22 / 88
38. Intersection
Question
Do line segments −−→p1p2 and −−→p3p4 intersect?
Very Simple!!! We have two possibilities
1 Each segment straddles the line containing the other.
2 An endpoint of one segment lies on the other segment.
23 / 88
39. Intersection
Question
Do line segments −−→p1p2 and −−→p3p4 intersect?
Very Simple!!! We have two possibilities
1 Each segment straddles the line containing the other.
2 An endpoint of one segment lies on the other segment.
23 / 88
40. Intersection
Question
Do line segments −−→p1p2 and −−→p3p4 intersect?
Very Simple!!! We have two possibilities
1 Each segment straddles the line containing the other.
2 An endpoint of one segment lies on the other segment.
23 / 88
41. Case I This summarize the previous two possibilities
The segments straddle each other’s lines.
Oposite Signs
Figure: Using Cross Products to find intersections
24 / 88
42. Case II No intersection
The segment straddles the line, but the other does not straddle the
other line
Same Signs
Figure: Using Cross Products to find that there is no intersection
25 / 88
43. Code
Code
Segment-Intersection(p1, p2, p3, p4)
1 d1 = Direction (p3, p4, p1)
2 d2 = Direction (p3, p4, p2)
3 d3 = Direction (p1, p2, p3)
4 d4 = Direction (p1, p2, p4)
5 if ((d1 > 0 and d2 < 0) or (d1 < 0 and d2 > 0) and
6 (d3 > 0 and d4 < 0) or (d3 < 0 and d4 > 0))
7 return TRUE
Figure: The Incomplete Code, You still need to test for endpoints over the
segment
26 / 88
44. Code
Code
Segment-Intersection(p1, p2, p3, p4)
1 d1 = Direction (p3, p4, p1)
2 d2 = Direction (p3, p4, p2)
3 d3 = Direction (p1, p2, p3)
4 d4 = Direction (p1, p2, p4)
5 if ((d1 > 0 and d2 < 0) or (d1 < 0 and d2 > 0) and
6 (d3 > 0 and d4 < 0) or (d3 < 0 and d4 > 0))
7 return TRUE
Figure: The Incomplete Code, You still need to test for endpoints over the
segment
26 / 88
45. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
27 / 88
46. Sweeping
Sweeping
Use an imaginary vertical line to pass through the n segments with events
x ∈ {r, t, u}:
Figure: Vertical Line to Record Events
28 / 88
47. Thus
This can be used to record events given two segments s1 and s2
Event I: s1 above s2 at x, written s1 x s2.
This is a total preorder relation for segment intersecting the
line at x.
The relation is transitive and reflexive.
Event II: s1 intersect s2, then neither s1 x s2 or s2 x s1, or
both (if s1 and s2 intersect at x)
29 / 88
48. Thus
This can be used to record events given two segments s1 and s2
Event I: s1 above s2 at x, written s1 x s2.
This is a total preorder relation for segment intersecting the
line at x.
The relation is transitive and reflexive.
Event II: s1 intersect s2, then neither s1 x s2 or s2 x s1, or
both (if s1 and s2 intersect at x)
29 / 88
49. Thus
This can be used to record events given two segments s1 and s2
Event I: s1 above s2 at x, written s1 x s2.
This is a total preorder relation for segment intersecting the
line at x.
The relation is transitive and reflexive.
Event II: s1 intersect s2, then neither s1 x s2 or s2 x s1, or
both (if s1 and s2 intersect at x)
29 / 88
50. Thus
This can be used to record events given two segments s1 and s2
Event I: s1 above s2 at x, written s1 x s2.
This is a total preorder relation for segment intersecting the
line at x.
The relation is transitive and reflexive.
Event II: s1 intersect s2, then neither s1 x s2 or s2 x s1, or
both (if s1 and s2 intersect at x)
29 / 88
52. Change in direction
When e and f intersect, e v f and f w e. In the Shaded Region,
any sweep line will have e and f as consecutive
V z w
Figure: Vertical Line to Record Events
31 / 88
53. Moving the sweep line
Something Notable
Sweeping algorithms typically manage two sets of data.
Sweep-line status
The sweep-line status gives the relationships among the objects that the
sweep line intersects.
Event-point schedule
The event-point schedule is a sequence of points, called event points,
which we order from left to right according to their x-coordinates.
As the sweep progress from left to right, it stops and processes each
event point, then resumes.
It is possible to use a min-priority queue to keep those event points
sorted by x-coordinate.
32 / 88
54. Moving the sweep line
Something Notable
Sweeping algorithms typically manage two sets of data.
Sweep-line status
The sweep-line status gives the relationships among the objects that the
sweep line intersects.
Event-point schedule
The event-point schedule is a sequence of points, called event points,
which we order from left to right according to their x-coordinates.
As the sweep progress from left to right, it stops and processes each
event point, then resumes.
It is possible to use a min-priority queue to keep those event points
sorted by x-coordinate.
32 / 88
55. Moving the sweep line
Something Notable
Sweeping algorithms typically manage two sets of data.
Sweep-line status
The sweep-line status gives the relationships among the objects that the
sweep line intersects.
Event-point schedule
The event-point schedule is a sequence of points, called event points,
which we order from left to right according to their x-coordinates.
As the sweep progress from left to right, it stops and processes each
event point, then resumes.
It is possible to use a min-priority queue to keep those event points
sorted by x-coordinate.
32 / 88
56. Moving the sweep line
Something Notable
Sweeping algorithms typically manage two sets of data.
Sweep-line status
The sweep-line status gives the relationships among the objects that the
sweep line intersects.
Event-point schedule
The event-point schedule is a sequence of points, called event points,
which we order from left to right according to their x-coordinates.
As the sweep progress from left to right, it stops and processes each
event point, then resumes.
It is possible to use a min-priority queue to keep those event points
sorted by x-coordinate.
32 / 88
57. Sweeping Process
First
We sort the segment endpoints by increasing x-coordinate and
proceed from left to right.
However, sometimes they have the same x-coordinate (Covertical)
If two or more endpoints are covertical, we break the tie by putting all the
covertical left endpoints before the covertical right endpoints.
33 / 88
58. Sweeping Process
First
We sort the segment endpoints by increasing x-coordinate and
proceed from left to right.
However, sometimes they have the same x-coordinate (Covertical)
If two or more endpoints are covertical, we break the tie by putting all the
covertical left endpoints before the covertical right endpoints.
Covertical Left
End Points
Covertical Right
End Points
33 / 88
59. Then
Second
Within a set of covertical left endpoints, we put those with lower
y-coordinates first, and we do the same within a set of covertical right
endpoints.
Covertical Left
End Points
Covertical Right
End Points
FIRST
34 / 88
60. Then
Process
1 When we encounter a segment’s left endpoint, we insert the segment
into the sweep-line status.
2 We delete the segment from the sweep-line status upon encountering
its right endpoint.
Thus
Whenever two segments first become consecutive in the total preorder, we
check whether they intersect.
35 / 88
61. Then
Process
1 When we encounter a segment’s left endpoint, we insert the segment
into the sweep-line status.
2 We delete the segment from the sweep-line status upon encountering
its right endpoint.
Thus
Whenever two segments first become consecutive in the total preorder, we
check whether they intersect.
35 / 88
62. Then
Process
1 When we encounter a segment’s left endpoint, we insert the segment
into the sweep-line status.
2 We delete the segment from the sweep-line status upon encountering
its right endpoint.
Thus
Whenever two segments first become consecutive in the total preorder, we
check whether they intersect.
35 / 88
63. Operations
Operations to keep preorder on the events for algorithm
INSERT(T, s): insert segment s into T.
DELETE(T, s): delete segment s from T.
ABOVE(T, s): return the segment immediately above segment s in T.
BELOW(T, s): return the segment immediately below segment s in T.
Note
Each operation can be performed in O(log2 n) using a red-black-tree by
using comparisons by cross product to find the above and below.
This allows to see
The relative ordering of two segments.
36 / 88
64. Operations
Operations to keep preorder on the events for algorithm
INSERT(T, s): insert segment s into T.
DELETE(T, s): delete segment s from T.
ABOVE(T, s): return the segment immediately above segment s in T.
BELOW(T, s): return the segment immediately below segment s in T.
Note
Each operation can be performed in O(log2 n) using a red-black-tree by
using comparisons by cross product to find the above and below.
This allows to see
The relative ordering of two segments.
36 / 88
65. Operations
Operations to keep preorder on the events for algorithm
INSERT(T, s): insert segment s into T.
DELETE(T, s): delete segment s from T.
ABOVE(T, s): return the segment immediately above segment s in T.
BELOW(T, s): return the segment immediately below segment s in T.
Note
Each operation can be performed in O(log2 n) using a red-black-tree by
using comparisons by cross product to find the above and below.
This allows to see
The relative ordering of two segments.
36 / 88
66. Operations
Operations to keep preorder on the events for algorithm
INSERT(T, s): insert segment s into T.
DELETE(T, s): delete segment s from T.
ABOVE(T, s): return the segment immediately above segment s in T.
BELOW(T, s): return the segment immediately below segment s in T.
Note
Each operation can be performed in O(log2 n) using a red-black-tree by
using comparisons by cross product to find the above and below.
This allows to see
The relative ordering of two segments.
36 / 88
67. Operations
Operations to keep preorder on the events for algorithm
INSERT(T, s): insert segment s into T.
DELETE(T, s): delete segment s from T.
ABOVE(T, s): return the segment immediately above segment s in T.
BELOW(T, s): return the segment immediately below segment s in T.
Note
Each operation can be performed in O(log2 n) using a red-black-tree by
using comparisons by cross product to find the above and below.
This allows to see
The relative ordering of two segments.
36 / 88
68. Operations
Operations to keep preorder on the events for algorithm
INSERT(T, s): insert segment s into T.
DELETE(T, s): delete segment s from T.
ABOVE(T, s): return the segment immediately above segment s in T.
BELOW(T, s): return the segment immediately below segment s in T.
Note
Each operation can be performed in O(log2 n) using a red-black-tree by
using comparisons by cross product to find the above and below.
This allows to see
The relative ordering of two segments.
36 / 88
69. What the algorithm does?
Moving the sweeping line discretely - Event-point schedule
Here, moving through the x-axis
discrete events
Using the RBT
to Store the Info
about the segment
order
37 / 88
70. Event-Point Schedule Implementation
For this
We can use a Priority Queue using lexicographic order
The interesting part is the Sweeping-Line Satus
Because the way we build the balanced tree
38 / 88
71. Event-Point Schedule Implementation
For this
We can use a Priority Queue using lexicographic order
The interesting part is the Sweeping-Line Satus
Because the way we build the balanced tree
38 / 88
73. Sweeping Line Status Implementation
Use the following relation of order to build the binary tree
Given a segment x, then you insert y
Case I if y is counterclockwise, it is below x (Go to the left).
Case II if y is clockwise, it is above x (Go to the Right)
In addtion
If you are at a leaf do the insertion, but also insert the leaf at the left or
right given the insertion.
40 / 88
74. Sweeping Line Status Implementation
Use the following relation of order to build the binary tree
Given a segment x, then you insert y
Case I if y is counterclockwise, it is below x (Go to the left).
Case II if y is clockwise, it is above x (Go to the Right)
In addtion
If you are at a leaf do the insertion, but also insert the leaf at the left or
right given the insertion.
40 / 88
79. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
80. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
81. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
82. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
83. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
84. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
85. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
86. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
87. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
88. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
89. Pseudo-code with complexity O (n log2 n)
Any-Segment-Intersect(S)
1 T = ∅
2 Sort the endpoints of the segments in S from left to right
Breaking ties by putting left endpoints before right endpoints
and breaking further ties by putting points with lower
y−coordinates first
3 for each point p in the sorted list
4 if p is the left endpoint of a segment s
5 INSERT(T, s)
6 if (ABOVE(T, s) exists and intersect s)
or (BELOW(T, s) exists and intersect s)
7 return TRUE
8 if p is the right endpoint of a segment s
9 if (both ABOVE(T, s) and BELOW(T, s) exist)
and (ABOVE(T, s) intersect BELOW(T, s))
10 return TRUE
11 DELETE(T, s)
12 return FALSE 45 / 88
90. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
46 / 88
91. Correctness
The ANY-SEGMENTS-INTERSECT returns TRUE
If it finds an intersection between two of the input segments.
Proof:
Observation: What if there is the leftmost intersection, p?
Then, let a and b be the segments to intersect at p
Then, for a and b
Since no intersections occur to the left of p, the order given by T is
correct at all points to the left of p.
Assuming that no three segments intersect at the same point, a and b
become consecutive in the total preorder of some sweep line z.
47 / 88
92. Correctness
The ANY-SEGMENTS-INTERSECT returns TRUE
If it finds an intersection between two of the input segments.
Proof:
Observation: What if there is the leftmost intersection, p?
Then, let a and b be the segments to intersect at p
Then, for a and b
Since no intersections occur to the left of p, the order given by T is
correct at all points to the left of p.
Assuming that no three segments intersect at the same point, a and b
become consecutive in the total preorder of some sweep line z.
47 / 88
93. Correctness
The ANY-SEGMENTS-INTERSECT returns TRUE
If it finds an intersection between two of the input segments.
Proof:
Observation: What if there is the leftmost intersection, p?
Then, let a and b be the segments to intersect at p
Then, for a and b
Since no intersections occur to the left of p, the order given by T is
correct at all points to the left of p.
Assuming that no three segments intersect at the same point, a and b
become consecutive in the total preorder of some sweep line z.
47 / 88
94. Correctness
The ANY-SEGMENTS-INTERSECT returns TRUE
If it finds an intersection between two of the input segments.
Proof:
Observation: What if there is the leftmost intersection, p?
Then, let a and b be the segments to intersect at p
Then, for a and b
Since no intersections occur to the left of p, the order given by T is
correct at all points to the left of p.
Assuming that no three segments intersect at the same point, a and b
become consecutive in the total preorder of some sweep line z.
47 / 88
95. Correctness
The ANY-SEGMENTS-INTERSECT returns TRUE
If it finds an intersection between two of the input segments.
Proof:
Observation: What if there is the leftmost intersection, p?
Then, let a and b be the segments to intersect at p
Then, for a and b
Since no intersections occur to the left of p, the order given by T is
correct at all points to the left of p.
Assuming that no three segments intersect at the same point, a and b
become consecutive in the total preorder of some sweep line z.
47 / 88
96. Now, we have two cases
First Case
a
b
p
z SWEEPING LINE
48 / 88
97. First Case
Moreover
z is to the left of p or goes through p.
In addition
Exist a endpoint q where a and b become consecutive.
49 / 88
98. First Case
Moreover
z is to the left of p or goes through p.
In addition
Exist a endpoint q where a and b become consecutive.
a
b
p
z
q
49 / 88
99. Finally
Then a and b
They become consecutive in the total pre-order of a sweep line.
50 / 88
100. Case II
We have that q is a left endpoint where a and b stop being
consecutive
a
b
p
z
q
51 / 88
101. Correctness
Then, we need to handle two cases
1 if p is in the sweep line ⇒ p == q.
1 Observe that can be handled by using the idea of case II.
2 If not q is at the left of p and is the nearest left one:
1 This can be handled by the case I.
52 / 88
102. Correctness
Then, we need to handle two cases
1 if p is in the sweep line ⇒ p == q.
1 Observe that can be handled by using the idea of case II.
2 If not q is at the left of p and is the nearest left one:
1 This can be handled by the case I.
52 / 88
103. Correctness
Then, we need to handle two cases
1 if p is in the sweep line ⇒ p == q.
1 Observe that can be handled by using the idea of case II.
2 If not q is at the left of p and is the nearest left one:
1 This can be handled by the case I.
52 / 88
104. Correctness
Then, we need to handle two cases
1 if p is in the sweep line ⇒ p == q.
1 Observe that can be handled by using the idea of case II.
2 If not q is at the left of p and is the nearest left one:
1 This can be handled by the case I.
52 / 88
105. Case I
Either a or b is inserted into T, and the other segment is above or
below it in the total pre-order.
a
b
p
z
q
53 / 88
106. When is this detected?
In the following lines of the code
Lines 4–7 detect this case.
54 / 88
107. Case II
Segments a and b are already in T , and a segment between them in
the total pre-order is deleted, making a and b to become consecutive
a
b
p
z
qI
a
I
b
a
b
55 / 88
108. When is this detected?
In the following lines of the code
Lines 8–11 detect this case.
56 / 88
109. Running Time
Something Notable
1 Line 1 takes O(1) time.
2 Line 2 takes O(n log2 n) time, using merge or heap sort
3 The for loop iterates at most 2n times
1 Each iteration takes O (log2 n) in a well balanced tree.
2 Each intersection test takes O (1)
Total Time
O (n log2 n)
57 / 88
110. Running Time
Something Notable
1 Line 1 takes O(1) time.
2 Line 2 takes O(n log2 n) time, using merge or heap sort
3 The for loop iterates at most 2n times
1 Each iteration takes O (log2 n) in a well balanced tree.
2 Each intersection test takes O (1)
Total Time
O (n log2 n)
57 / 88
111. Running Time
Something Notable
1 Line 1 takes O(1) time.
2 Line 2 takes O(n log2 n) time, using merge or heap sort
3 The for loop iterates at most 2n times
1 Each iteration takes O (log2 n) in a well balanced tree.
2 Each intersection test takes O (1)
Total Time
O (n log2 n)
57 / 88
112. Running Time
Something Notable
1 Line 1 takes O(1) time.
2 Line 2 takes O(n log2 n) time, using merge or heap sort
3 The for loop iterates at most 2n times
1 Each iteration takes O (log2 n) in a well balanced tree.
2 Each intersection test takes O (1)
Total Time
O (n log2 n)
57 / 88
113. Running Time
Something Notable
1 Line 1 takes O(1) time.
2 Line 2 takes O(n log2 n) time, using merge or heap sort
3 The for loop iterates at most 2n times
1 Each iteration takes O (log2 n) in a well balanced tree.
2 Each intersection test takes O (1)
Total Time
O (n log2 n)
57 / 88
114. Running Time
Something Notable
1 Line 1 takes O(1) time.
2 Line 2 takes O(n log2 n) time, using merge or heap sort
3 The for loop iterates at most 2n times
1 Each iteration takes O (log2 n) in a well balanced tree.
2 Each intersection test takes O (1)
Total Time
O (n log2 n)
57 / 88
115. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
58 / 88
116. Convex Hull
Convex Hull
Given a set of points, Q, find the smallest convex polygon P such
that Q ⊂ P. This is denoted by CH(Q).
Bunch of Points in 2D
59 / 88
117. Convex Hull
Convex Hull
Given a set of points, Q, find the smallest convex polygon P such
that Q ⊂ P. This is denoted by CH(Q).
Their Convex Hull
60 / 88
118. Convex Hull
The two main Algorithms (Using the “Rotational Sweep”) that we are
going to explore
Graham’s Scan.
Jarvis’ March.
Nevertheless there are other methods
The incremental method
Divide-and-conquer method.
Prune-and-search method.
61 / 88
119. Convex Hull
The two main Algorithms (Using the “Rotational Sweep”) that we are
going to explore
Graham’s Scan.
Jarvis’ March.
Nevertheless there are other methods
The incremental method
Divide-and-conquer method.
Prune-and-search method.
61 / 88
120. Convex Hull
The two main Algorithms (Using the “Rotational Sweep”) that we are
going to explore
Graham’s Scan.
Jarvis’ March.
Nevertheless there are other methods
The incremental method
Divide-and-conquer method.
Prune-and-search method.
61 / 88
121. Convex Hull
The two main Algorithms (Using the “Rotational Sweep”) that we are
going to explore
Graham’s Scan.
Jarvis’ March.
Nevertheless there are other methods
The incremental method
Divide-and-conquer method.
Prune-and-search method.
61 / 88
122. Convex Hull
The two main Algorithms (Using the “Rotational Sweep”) that we are
going to explore
Graham’s Scan.
Jarvis’ March.
Nevertheless there are other methods
The incremental method
Divide-and-conquer method.
Prune-and-search method.
61 / 88
123. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
62 / 88
124. Graham’s Scan
Graham’s Scan Basics
It keeps a Stack of candidate points.
It Pops elements that are not part of the CH(Q).
Whatever is left in the Stack is part of the CH(Q).
63 / 88
125. Graham’s Scan
Graham’s Scan Basics
It keeps a Stack of candidate points.
It Pops elements that are not part of the CH(Q).
Whatever is left in the Stack is part of the CH(Q).
63 / 88
126. Graham’s Scan
Graham’s Scan Basics
It keeps a Stack of candidate points.
It Pops elements that are not part of the CH(Q).
Whatever is left in the Stack is part of the CH(Q).
63 / 88
127. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
128. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
129. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
130. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
131. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
132. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
133. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
134. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
135. Graham’s Scan Code
Algorithm
GRAHAM-SCAN(Q)
1. Let p0 be the point Q with
the minimum y-coordinate or
the leftmost such point in
case of a tie
2. let p1, p2, ..., pn be the
remaining points in Q, sorted
by polar angle in counter
clockwise order around p0 (If
more than one point has the
same angle, remove all but
one that is farthest from p0)
3. Let S be an empty stack
4. PUSH(p0, S)
5. PUSH(p1, S)
6. PUSH(p2, S)
7. for i = 3 to n
8. while ccw(next-top(S), pi, top (S)) ≤ 0
9. POP(S)
10. PUSH(S)
11. return S
The clockwise and counter clockwise algorithm
ccw(p1, p2, p3)
1. return (p3 − p1 × p2 − p1)
64 / 88
148. We have the following theorem for correctness of the
algorithm
Theorem 33.1 (Correctness of Graham’s scan)
If GRAHAM-SCAN executes on a set Q of points, where |Q| ≥ 3, then at
termination, the stack S consists of, from bottom to top, exactly the
vertices of CH(Q) in counterclockwise order.
The proof is based in loop invariance
I leave this to you to read!!!
77 / 88
149. We have the following theorem for correctness of the
algorithm
Theorem 33.1 (Correctness of Graham’s scan)
If GRAHAM-SCAN executes on a set Q of points, where |Q| ≥ 3, then at
termination, the stack S consists of, from bottom to top, exactly the
vertices of CH(Q) in counterclockwise order.
The proof is based in loop invariance
I leave this to you to read!!!
77 / 88
150. Using Aggregate Analysis to obtain the complexity
O (n log2 n)
Complexity
1 Line 2 takes O (n log2 n) using Merge sort or Heap sort by using polar
angles and cross product.
2 Lines 3-6 take O (1).
For the Lines 7-10
The for loop executes at most n − 3 times because we have |Q| − 3 points
left
78 / 88
151. Using Aggregate Analysis to obtain the complexity
O (n log2 n)
Complexity
1 Line 2 takes O (n log2 n) using Merge sort or Heap sort by using polar
angles and cross product.
2 Lines 3-6 take O (1).
For the Lines 7-10
The for loop executes at most n − 3 times because we have |Q| − 3 points
left
78 / 88
152. Using Aggregate Analysis to obtain the complexity
O (n log2 n)
Complexity
1 Line 2 takes O (n log2 n) using Merge sort or Heap sort by using polar
angles and cross product.
2 Lines 3-6 take O (1).
For the Lines 7-10
The for loop executes at most n − 3 times because we have |Q| − 3 points
left
78 / 88
153. In addition
Given
PUSH takes O(1) time:
Each iteration takes O (1) time not taking in account the time spent
in the while loop in lines 8-9.
Then
The for loop take overall time O(n) time
Here is the aggregate analysis
Here, we will prove that the overall time for all the times the while loop is
touched by the for loop is going to be O (n).
79 / 88
154. In addition
Given
PUSH takes O(1) time:
Each iteration takes O (1) time not taking in account the time spent
in the while loop in lines 8-9.
Then
The for loop take overall time O(n) time
Here is the aggregate analysis
Here, we will prove that the overall time for all the times the while loop is
touched by the for loop is going to be O (n).
79 / 88
155. In addition
Given
PUSH takes O(1) time:
Each iteration takes O (1) time not taking in account the time spent
in the while loop in lines 8-9.
Then
The for loop take overall time O(n) time
Here is the aggregate analysis
Here, we will prove that the overall time for all the times the while loop is
touched by the for loop is going to be O (n).
79 / 88
156. Aggregate Analysis
We have that
For i = 0, 1, ..., n, we push each point pi into the stack S exactly once.
Remember Multipop?
We can pop at most the number of items that we push on it.
Thus
At least three points p0, p1 and pm are never popped out of the stack!!!
pm is the last point being taken in consideration!!! With m ≤ n
80 / 88
157. Aggregate Analysis
We have that
For i = 0, 1, ..., n, we push each point pi into the stack S exactly once.
Remember Multipop?
We can pop at most the number of items that we push on it.
Thus
At least three points p0, p1 and pm are never popped out of the stack!!!
pm is the last point being taken in consideration!!! With m ≤ n
80 / 88
158. Aggregate Analysis
We have that
For i = 0, 1, ..., n, we push each point pi into the stack S exactly once.
Remember Multipop?
We can pop at most the number of items that we push on it.
Thus
At least three points p0, p1 and pm are never popped out of the stack!!!
pm is the last point being taken in consideration!!! With m ≤ n
80 / 88
159. Aggregate Analysis
Thus
We have m − 2 POP operations are performed in total!!! If we had pushed
m elements into S.
Thus, each iteration of the while loop
It performs one POP, and there are at most m − 2 iterations of the while
loop altogether.
Now
Given that the test in line 8 takes O(1) times, each call of the POP takes
O(1) and m ≤ n − 1.
81 / 88
160. Aggregate Analysis
Thus
We have m − 2 POP operations are performed in total!!! If we had pushed
m elements into S.
Thus, each iteration of the while loop
It performs one POP, and there are at most m − 2 iterations of the while
loop altogether.
Now
Given that the test in line 8 takes O(1) times, each call of the POP takes
O(1) and m ≤ n − 1.
81 / 88
161. Aggregate Analysis
Thus
We have m − 2 POP operations are performed in total!!! If we had pushed
m elements into S.
Thus, each iteration of the while loop
It performs one POP, and there are at most m − 2 iterations of the while
loop altogether.
Now
Given that the test in line 8 takes O(1) times, each call of the POP takes
O(1) and m ≤ n − 1.
81 / 88
162. Aggregate Analysis
We have that
The total time of the while loop is O (n).
Finally
The Running Time of GRAHAM − SCAN is O (n log2 n)
82 / 88
163. Aggregate Analysis
We have that
The total time of the while loop is O (n).
Finally
The Running Time of GRAHAM − SCAN is O (n log2 n)
82 / 88
164. Outline
1 Introduction
What is Computational Geometry?
2 Representation
Representation of Primitive Geometries
3 Line-Segment Properties
Using Point Representation
Cross Product
Turn Left or Right
Intersection
4 Classical Problems
Determining whether any pair of segments intersects
Correctness of Sweeping Line Algorithm
Finding the Convex Hull
Graham’s Scan
Jarvis’ March
83 / 88
165. Jarvis’ March
Jarvis’ March Basics
It computes CH by using
A technique called Package Wrapping.
At each point calculate the minimum polar angle.
Create a left and right chain with the convex hull points.
84 / 88
166. Jarvis’ March
Jarvis’ March Basics
It computes CH by using
A technique called Package Wrapping.
At each point calculate the minimum polar angle.
Create a left and right chain with the convex hull points.
84 / 88
167. Jarvis’ March
Jarvis’ March Basics
It computes CH by using
A technique called Package Wrapping.
At each point calculate the minimum polar angle.
Create a left and right chain with the convex hull points.
84 / 88
168. Jarvis’ March
Jarvis’ March Basics
It computes CH by using
A technique called Package Wrapping.
At each point calculate the minimum polar angle.
Create a left and right chain with the convex hull points.
84 / 88
169. Formally
Jarvis’s march builds a sequence
H = p0, p1, p2, ..., ph−1 of the vertices of CH(Q)
First
We start with p0 the next vertex p1 in the convex hull has the smallest
polar angle with respect to p0.
Next
p2 has the smallest polar angle with respect to p1.
85 / 88
170. Formally
Jarvis’s march builds a sequence
H = p0, p1, p2, ..., ph−1 of the vertices of CH(Q)
First
We start with p0 the next vertex p1 in the convex hull has the smallest
polar angle with respect to p0.
Next
p2 has the smallest polar angle with respect to p1.
85 / 88
171. Formally
Jarvis’s march builds a sequence
H = p0, p1, p2, ..., ph−1 of the vertices of CH(Q)
First
We start with p0 the next vertex p1 in the convex hull has the smallest
polar angle with respect to p0.
Next
p2 has the smallest polar angle with respect to p1.
85 / 88
172. Now
Then
When we reach the highest vertex, pk (Breaking ties by choosing the
farthest such vertex), we have constructed the right chain of CH(Q).
To construct the left chain
We start at pk, then we choose pk+1 as the point with the smallest polar
angle with respect to pk negative , but from the negative x-axis.
Next
The next point is selected in the same manner until we have reached p0.
86 / 88
173. Now
Then
When we reach the highest vertex, pk (Breaking ties by choosing the
farthest such vertex), we have constructed the right chain of CH(Q).
To construct the left chain
We start at pk, then we choose pk+1 as the point with the smallest polar
angle with respect to pk negative , but from the negative x-axis.
Next
The next point is selected in the same manner until we have reached p0.
86 / 88
174. Now
Then
When we reach the highest vertex, pk (Breaking ties by choosing the
farthest such vertex), we have constructed the right chain of CH(Q).
To construct the left chain
We start at pk, then we choose pk+1 as the point with the smallest polar
angle with respect to pk negative , but from the negative x-axis.
Next
The next point is selected in the same manner until we have reached p0.
86 / 88
175. Jarvis’ March
Example
LEFT CHAIN RIGHT CHAIN
Figure: Wrapping the Gift. Here the Right Chain finishes at p6, then
the Left Chain is started
87 / 88