-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何判断4个点坐标是左上角\左下角\右上角\右下角 #13
Comments
很不错的方案,但是给的四个点并不知道哪两个是对角线顶点,可能是AB,AC 或者 AD,需要遍历一下。由于哪个是左上并没有明确的定义,所以可以简单的以离原点最近的点作为 左上,之后再连线判断另外两个点是否在线的两侧来判断对角线,具体实现可以看:
|
OK, 明白了,谢谢 |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我看到了你的一个帖子: https://www.v2ex.com/t/381107
已知四个点的坐标A(x1, y1) B(x2, y2) C(x3, y3) D(x4, y4) ,如何确定这四个点分别为 左上,右上,右下,左下。
我想到了凸四边形的解决方案:
备注:如果ABCD不确定是依次的4个点,那么交点要么是连接AC、BD,要么就是连接AB、CD。两条直线如果平行(例如AC、BD平行),那么就是另外一种情况必然是相交的两条线(就直接取AB、CD的交点);如果均不平行,就判断相交的点是否在四边形内,在四边形内的就是交点
The text was updated successfully, but these errors were encountered: