当前位置:网站首页>Graham's Scan method for solving convex hull problems
Graham's Scan method for solving convex hull problems
2022-07-31 15:54:00 【Yasen Jia】
Question background
- About the convex hull
Assuming that there are 13 points p0~p12 on the plane, make a polygon through some points, so that this polygon can "enclose" all the points, when the polygon is a convex polygon,We call this the "convex hull" - Convex Hull Problem
On a two-dimensional coordinate system, each point can be represented by coordinates (x,y)
Given the number of points and the coordinates of each point, find the points that form the convex hull
Graham’s Scan method
Find a point on the convex hull first, and start from that point to find the points on the convex hull one by one in a counterclockwise direction
Steps
Put all points in the two-dimensional coordinate system, then the point with the smallest ordinate must be the point on the convex hull, as shown in the figure p0
Translate the coordinates of all points to make p0 as the origin, as shown above
Calculate the argument of each point with respect to p0 α \alpha α, sorts the points in ascending order of argument.When α \alpha α When the points are the same, the points closer to p0 are ranked first.For example, the results obtained in the above figure are p1, p2, p3, p4, p5, p6, p7, p8.It can be known from geometric knowledge that the first point p1 and the last point p8 must be points on the convex hull
Now that we know the first point p0 and the second point p1 on the convex hull, we put them on the stack in turn.
Initialize the current point to p2, and perform the following operations:
a. Determine the difference between the vector formed by the two points at the top of the stack and the vector formed by the stack vertex and the current pointWhether the relationship is counterclockwise, that is, whether the vector obtained after the cross product is counterclockwise.(Another formulation of this question is to connect two points at the top of the stack to get a straight line to see if the current point is to the left of the straight line)b. If so, the current point is the point on the convex hull, and it is pushed into the stack.And take the next point in the sorting as the current point, and continue to judge a until all points are traversed.c. If not, the top element of the stack is not a point on the convex hull, and the top element of the stack is popped.The current point remains unchanged, and the judgment of a continues until it is a counterclockwise relationship.After the final traversal, the elements in the stack are the points that form the convex hull
Flowchart

Code Link
边栏推荐
- TextBlock控件入门基础工具使用用法,取上法入门
- Character pointer assignment [easy to understand]
- BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)
- Synchronized and volatile interview brief summary
- t-sne 数据可视化网络中的部分参数+
- 双边滤波加速「建议收藏」
- ML.NET相关资源整理
- SIGABRT 报错时的注意事项和解决方法
- Applicable scenario of multi-master replication (2) - client and collaborative editing that require offline operation
- Deployment应用生命周期与Pod健康检查
猜你喜欢

Why is the field of hacking almost filled with boys?

BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)

TRACE32 - C source code association

.NET 20th Anniversary Interview - Zhang Shanyou: How .NET technology empowers and changes the world

Kubernetes common commands
![[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development](/img/f6/311d5a4c70993df6291250d2025d3f.jpg)
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development

Grafana安装后web打开报错

Premiere Pro 2022 for (pr 2022)v22.5.0

mysql黑窗口~建库建表

腾讯云部署----DevOps
随机推荐
Use of radiobutton
JVM parameter analysis Xmx, Xms, Xmn, NewRatio, SurvivorRatio, PermSize, PrintGC "recommended collection"
How does automated testing create business value?
arm按键控制led灯闪烁(嵌入式按键实验报告)
双边滤波加速「建议收藏」
ML.NET相关资源整理
TextBlock控件入门基础工具使用用法,取上法入门
软件实现AT命令操作过程
WPF project - basic usage of controls entry, you must know XAML
ansible学习笔记02
The R language ggstatsplot package ggbarstats function visualizes bar charts, and adds hypothesis test results (including sample number, statistics, effect size and its confidence interval, significan
11 pinia use
Codeforces Round #796 (Div. 2)(A-D)
全新宝马3系上市,安全、舒适一个不落
6-22 Vulnerability exploit - postgresql database password cracking
MySQL的相关问题
数据库的范式(第一范式,第二范式,第三范式,BCNF范式)「建议收藏」
7. Summary of common interview questions
国内市场上的BI软件,到底有啥区别
字符串反转的实现方法总结「建议收藏」