It is related to Analysis and Design Of Algorithms Subject.Basically it describe basic of topological sorting, it's algorithm and step by step process to solve the example of topological sort.
It is related to Analysis and Design Of Algorithms Subject.Basically it describe basic of topological sorting, it's algorithm and step by step process to solve the example of topological sort.
Cohen-Sutherland Line Clipping Algorithm:
When drawing a 2D line on screen, it might happen that one or both of the endpoints are outside the screen while a part of the line should still be visible. In that case, an efficient algorithm is needed to find two new endpoints that are on the edges on the screen, so that the part of the line that's visible can now be drawn. This way, all those points of the line outside the screen are clipped away and you don't need to waste any execution time on them.
A good clipping algorithm is the Cohen-Sutherland algorithm for this solution.
By,
Maruf Abdullah Rion
The solution to the single-source shortest-path tree problem in graph theory. This slide was prepared for Design and Analysis of Algorithm Lab for B.Tech CSE 2nd Year 4th Semester.
In mathematics, graph theory is the study of graphs, which are mathematical structures used to model pairwise relations between objects.Graph theory is also important in real life.
This presentation gives a conceptual idea of a graphical algorithm that is Dijkstra's Algorithm. Includes general introduction , the pseudocode, code in form of QR Card, graphical. Also discussing the algorithm in form of graphical images and nodes. Also it include the complexity and application of algorithm in various ranges of fields. This is a fun, eye-catching, conceptual presentation, best suited for students into engineering.
One of the main reasons for the popularity of Dijkstra's Algorithm is that it is one of the most important and useful algorithms available for generating (exact) optimal solutions to a large class of shortest path problems. The point being that this class of problems is extremely important theoretically, practically, as well as educationally.
Closures of Relations
CMSC 56 | Discrete Mathematical Structure for Computer Science
November 20, 2018
Instructor: Allyn Joy D. Calcaben
College of Arts & Sciences
University of the Philippines Visayas
Cohen-Sutherland Line Clipping Algorithm:
When drawing a 2D line on screen, it might happen that one or both of the endpoints are outside the screen while a part of the line should still be visible. In that case, an efficient algorithm is needed to find two new endpoints that are on the edges on the screen, so that the part of the line that's visible can now be drawn. This way, all those points of the line outside the screen are clipped away and you don't need to waste any execution time on them.
A good clipping algorithm is the Cohen-Sutherland algorithm for this solution.
By,
Maruf Abdullah Rion
The solution to the single-source shortest-path tree problem in graph theory. This slide was prepared for Design and Analysis of Algorithm Lab for B.Tech CSE 2nd Year 4th Semester.
In mathematics, graph theory is the study of graphs, which are mathematical structures used to model pairwise relations between objects.Graph theory is also important in real life.
This presentation gives a conceptual idea of a graphical algorithm that is Dijkstra's Algorithm. Includes general introduction , the pseudocode, code in form of QR Card, graphical. Also discussing the algorithm in form of graphical images and nodes. Also it include the complexity and application of algorithm in various ranges of fields. This is a fun, eye-catching, conceptual presentation, best suited for students into engineering.
One of the main reasons for the popularity of Dijkstra's Algorithm is that it is one of the most important and useful algorithms available for generating (exact) optimal solutions to a large class of shortest path problems. The point being that this class of problems is extremely important theoretically, practically, as well as educationally.
Closures of Relations
CMSC 56 | Discrete Mathematical Structure for Computer Science
November 20, 2018
Instructor: Allyn Joy D. Calcaben
College of Arts & Sciences
University of the Philippines Visayas
View classification of medical x ray images using pnn classifier, decision tr...eSAT Journals
Abstract: In this era of electronic advancements in the field of medical image processing, the quantum of medical X-ray images so produced exorbitantly can be effectively addressed by means of automated indexing, comparing, analysing and annotating that will really be pivotal to the radiologists in interpreting and diagnosing the diseases. In order to envisage such an objective, it has been humbly endeavoured in this paper by proposing an efficient methodology that takes care of the view classification of the X-ray images for the automated annotation from their vast database, with which the decision making for the physicians and radiologists becomes simpler despite an immeasurable and ever-growing trends of the X-ray images. In this paper, X-ray images of six different classes namely chest, head, foot, palm, spine and neck have been collected. The framework proposed in this paper involves the following: The images are pre-processed using M3 filter and segmentation by Expectation Maximization (EM) algorithm, followed by feature extraction through Discrete Wavelet Transform. The orientation of X-ray images has been performed in this work by comparing among the Probabilistic Neural Network (PNN), Decision Tree algorithm and Support Vector Machine (SVM), while the PNN yields an accuracy of 75%, the Decision Tree with 92.77% and the SVM of 93.33%. Key Words: M3 filter, Expectation Maximaization, Discrete Wavelet Transformation, Probabilistic Neural Network, Decision Tree Algorithm and Support Vector Machine.
Mri brain image segmentatin and classification by modified fcm &svm akorithmeSAT Journals
Abstract Brain Tumor detection is challenging task in biomedical field. Image segmentation is a key step from the image processing to image analysis, it occupy an important place. The manual segmentation of brain image is challenging and time consuming task. An automated system overcomes the drawbacks as well as it segments the white matter, grey matter, cerebrospinal fluid and edema. This clustering approach is particularly used for brain tumor detection in abnormal MR images. In this paper the application of Modified FCM algorithm for Brain tumor detection and its classification by SVM algorithm is focused. The Magnetic Resonance image is converted in to vector format and that is given as input to the modified fuzzy c-means algorithm. In modified fuzzy c-means the steps are: initial fuzzy partitioning and fuzzy membership generation Cluster updation based on objective function, Assigning labels to pixels of each category and display segmented image that will give more meaningful regions to analyze. This clustered images served as inputs to SVM. The basic SVM takes a set of input data and predicts, for each given input, which of two possible classes. Keywords: Clustering, Classification, Fuzz C-Means, Support Vector Machine, MRI, Brain Tumor.
Patent Basics and Intellectual Property Rights Rahul Dev
Intellectual Property Rights, Basics of Patents, Case Studies & Examples for Business Owners Technology Companies, Startups and Research Institutes - Expert insights by patent attorneys and international business lawyers - http://www.techlaw.attorney
In machine learning, support vector machines (SVMs, also support vector networks[1]) are supervised learning models with associated learning algorithms that analyze data and recognize patterns, used for classification and regression analysis. The basic SVM takes a set of input data and predicts, for each given input, which of two possible classes forms the output, making it a non-probabilistic binary linear classifier.
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.
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
Trigonometric Function of General Angles LectureFroyd Wess
More: www.PinoyBIX.org
Lesson Objectives
Trigonometric Functions of Angles
Trigonometric Function Values
Could find the Six Trigonometric Functions
Learn the signs of functions in different Quadrants
Could easily determine the signs of each Trigonometric Functions
Solve problems involving Quadrantal Angles
Find Coterminal Angles
Learn to solve using reference angle
Solve problems involving Trigonometric Functions of Common Angles
Solve problems involving Trigonometric Functions of Uncommon Angles
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
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.
Explore the innovative world of trenchless pipe repair with our comprehensive guide, "The Benefits and Techniques of Trenchless Pipe Repair." This document delves into the modern methods of repairing underground pipes without the need for extensive excavation, highlighting the numerous advantages and the latest techniques used in the industry.
Learn about the cost savings, reduced environmental impact, and minimal disruption associated with trenchless technology. Discover detailed explanations of popular techniques such as pipe bursting, cured-in-place pipe (CIPP) lining, and directional drilling. Understand how these methods can be applied to various types of infrastructure, from residential plumbing to large-scale municipal systems.
Ideal for homeowners, contractors, engineers, and anyone interested in modern plumbing solutions, this guide provides valuable insights into why trenchless pipe repair is becoming the preferred choice for pipe rehabilitation. Stay informed about the latest advancements and best practices in the field.
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.
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
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.
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
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.
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.
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
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 / 90
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 / 90
5. Field of Application
VLSI design - Generation for Fast Voronoi Diagrams for Massive
Layouts Under Strict Distances to avoid Tunneling Effects!!
5 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
36. Code for this
We have the following code
Direction(pi, pj, pk)
1 return (pk − pi) × (pj − pi)
21 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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 / 90
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
(Sweeping Line Data Structure) 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 / 90
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
(Sweeping Line Data Structure) 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 / 90
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
(Sweeping Line Data Structure) 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 / 90
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
(Sweeping Line Data Structure) 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 / 90
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
(Sweeping Line Data Structure) 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 / 90
96. Now, we have two possbibilities
Case I
a
b
p
z SWEEPING LINE
48 / 90
97. Case I
Moreover
z is to the left of p or goes through p.
In addition
There is a endpoint q where a and b become consecutive.
49 / 90
98. Case I
Moreover
z is to the left of p or goes through p.
In addition
There is a endpoint q where a and b become consecutive.
a
b
p
z
q
49 / 90
99. Finally
Then a and b
They become consecutive in the total pre-order of a sweep line.
50 / 90
100. Case II
We have that q is a left endpoint where a and b stop being
consecutive
a
b
p
z
q
51 / 90
101. Correctness about the order given by T
Then, given the two following cases
1 if p is in the sweep line ⇒ p == q.
2 If q is at the left of p, and it is the nearest left one.
52 / 90
102. Correctness about the order given by T
Then, given the two following cases
1 if p is in the sweep line ⇒ p == q.
2 If q is at the left of p, and it is the nearest left one.
52 / 90
103. Do we mantain the correct preorder?
We have that given that p is first
Then, it is processed first becacuse the lexicographic order.
Therefore, two cases can happen
1 The point is processed - then the algorithm returns true
2 If the event is not processed - then the algorithm must have returned
true
53 / 90
104. Do we mantain the correct preorder?
We have that given that p is first
Then, it is processed first becacuse the lexicographic order.
Therefore, two cases can happen
1 The point is processed - then the algorithm returns true
2 If the event is not processed - then the algorithm must have returned
true
53 / 90
105. Handling Case I
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
54 / 90
106. When is this detected?
In the following lines of the code
Lines 8–11 detect this case.
55 / 90
107. Handling Case II
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
56 / 90
108. When is this detected?
In the following lines of the code
Lines 4–7 detect this case.
57 / 90
109. Finally
If event point q is not processed
It must have found an earlier intersection!!!
Therefore
If there is an intersection Any-Segment-Intersect returns true all the time
58 / 90
110. Finally
If event point q is not processed
It must have found an earlier intersection!!!
Therefore
If there is an intersection Any-Segment-Intersect returns true all the time
58 / 90
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)
59 / 90
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)
59 / 90
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)
59 / 90
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)
59 / 90
115. 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)
59 / 90
116. 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)
59 / 90
117. 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
60 / 90
118. 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
61 / 90
119. 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
62 / 90
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.
63 / 90
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.
63 / 90
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.
63 / 90
123. 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.
63 / 90
124. 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.
63 / 90
125. 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
64 / 90
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).
65 / 90
127. 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).
65 / 90
128. 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).
65 / 90
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)
66 / 90
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)
66 / 90
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)
66 / 90
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)
66 / 90
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)
66 / 90
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)
66 / 90
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)
66 / 90
136. 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)
66 / 90
137. 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)
66 / 90
150. 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!!!
79 / 90
151. 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!!!
79 / 90
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
80 / 90
153. 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
80 / 90
154. 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
80 / 90
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).
81 / 90
156. 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).
81 / 90
157. 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).
81 / 90
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
82 / 90
159. 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
82 / 90
160. 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
82 / 90
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.
83 / 90
162. 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.
83 / 90
163. 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.
83 / 90
164. 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)
84 / 90
165. 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)
84 / 90
166. 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
85 / 90
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.
86 / 90
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.
86 / 90
169. 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.
86 / 90
170. 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.
86 / 90
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.
87 / 90
172. 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.
87 / 90
173. 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.
87 / 90
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.
88 / 90
175. 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.
88 / 90
176. 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.
88 / 90
177. Jarvis’ March
Example
LEFT CHAIN RIGHT CHAIN
Figure: Wrapping the Gift. Here the Right Chain finishes at p6, then
the Left Chain is started
89 / 90