How to tell whether a point is to the right or left side of a line(如何判断一个点是在一条线的右侧还是左侧)
问题描述
我有一组点.我想将它们分成 2 个不同的集合.为此,我选择了两个点(a 和 b)并在它们之间画一条假想线.现在我想把这条线左边的所有点放在一组中,把这条线右边的点放在另一组中.
I have a set of points. I want to separate them into 2 distinct sets. To do this, I choose two points (a and b) and draw an imaginary line between them. Now I want to have all points that are left from this line in one set and those that are right from this line in the other set.
我如何判断任何给定点 z 是在左边还是在右边?我试图计算 a-z-b – 之间的角度.小于 180 的角度在右侧,大于 180 的角度在左侧.但由于 ArcCos 的定义,计算出的角度总是小于 180°.是否有计算大于 180° 的角度的公式(或任何其他选择右侧或左侧的公式)?
How can I tell for any given point z whether it is in the left or in the right set? I tried to calculate the angle between a-z-b – angles smaller than 180 are on the right hand side, greater than 180 on the left hand side – but because of the definition of ArcCos, the calculated angles are always smaller than 180°. Is there a formula to calculate angles greater than 180° (or any other formula to chose right or left side)?
推荐答案
使用向量行列式的符号(AB,AM),其中M(X,Y)为查询点:
Use the sign of the determinant of vectors (AB,AM), where M(X,Y) is the query point:
position = sign((Bx - Ax) * (Y - Ay) - (By - Ay) * (X - Ax))
一行是0,一侧是+1,另一侧是-1.
It is 0 on the line, and +1 on one side, -1 on the other side.
这篇关于如何判断一个点是在一条线的右侧还是左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何判断一个点是在一条线的右侧还是左侧
基础教程推荐
- 将数据集转换为列表 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
