确定一个点是否位于任意形状内? [英] determine if a point sits inside an arbitrary shape?

查看:19
本文介绍了确定一个点是否位于任意形状内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个点的坐标,我如何确定它是否在任意形状内?

Given a point's coordinates, how can I determine if it is within an arbitrary shape?

形状由点数组定义,我不知道形状在哪里闭合",我真正需要帮助的部分是找出形状闭合的位置.

The shape is defined by an array of points, I do not know where the shape is 'closed', the part I really need help is to work out where the shape is closed.

这里有一张图片可以更好地说明我的意思:

Here's an image to illustrate what I mean a little better:

推荐答案

最简单的方法是从该点投射一条光线并计算它穿过边界的次数.如果是奇数,则点在里面,偶数点在外面.

Easiest way to do it is cast a ray from that point and count how many times it crosses the boundary. If it is odd, the point is inside, even the point is outside.

维基:http://en.wikipedia.org/wiki/Point_in_polygon

请注意,这只适用于多种形状.

Note that this only works for manifold shapes.

这篇关于确定一个点是否位于任意形状内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆