如何检查一个点是否在三角形中?
你好 还要考虑到我有 4 个点,我将有 4 个三角形,我如何检查这四个三角形中的每个点是否是三角形内的点。 谢谢
Hi
also consider that I have 4 points and I will have 4 triangles how can I check these four triangles for each point that is the point within the triangles or not.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Polygon
实现Shape
接口,它提供了多个contains()
方法。这是一个简单的示例。Polygon
implements theShape
interface, which provides severalcontains()
methods. Here's a simple example.您需要找到三角形每条边创建的直线的方程,然后对于每条边,检查相关点是否与三角形中的第三个点位于该直线的同一侧。如果三者都在同一边,则它在三角形内。添加边界检查点落在一侧的情况。
You need to find the equation for the line created by each side of the triangle, and then for each side, check whether the point in question is on the same side of this line as the third point in the triangle. If all three are on the same side, it is within the triangle. Add bounds checking for cases of a point falling ON one of your sides.