如何判断一个点是在多边形的上方还是下方,而不是在多边形的内部?
我正在学习计算机图形学课程。在 3D 中,我有一个点和一个多边形,我想确定这个点位于我的多边形上方或下方。提前感谢您的回复。
I am taking Computer Graphics course.In 3D,I have a point and a polygon and I want to determine this point is located above or below my polygon.Thanks for your replies,in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果位于多边形所在平面的上方或下方即可,则可以将点在平面法线上的点积与平面上任何点的点积进行比较。或者,如果您愿意,可以查看法线与从平面上的点到该点的向量之间的点积的符号。
要检查它是否实际上是“上方”或“下方”,即直接位于上方或下方(即,不是偏离某处的侧面),然后通过沿法线将整个物体投影到 2d 中,然后在多边形中做一个点,然后沿着正常测试的距离。
If above or below the plane on which the polygon is resting will do, you can compare the dot product of the point onto the plane normal and that of any point on the plane. Or look at the sign of the dot product between the normal and a vector from a point on the plane to the point, if you prefer.
To check whether it is actually 'above' or 'below' in the sense of being directly above or below (ie, not off to the side somewhere) then do a point in polygon by projecting the whole thing into 2d along the normal and then a distance along normal test.
这取决于您对上方和下方的定义,让我首先谈谈简单的情况:
好吧,现在更难的解释是:点在多边形的哪一边。
除非它是共面的,否则您无法立即确定多边形。因此,如果它是非共面的,您必须将其细分为三角形并为每个三角形做出决定。
对于一个三角形,您可以决定一个点是在它的上方还是下方(在 3D 中),首先计算构成三角形边的 2 个向量的叉积;这将定义一个方向(=“上方”和“下方”的定义),这取决于您使用这两个向量的顺序,所以要小心。然后计算新向量(称为该三角形的垂线)以及测试点和三角形底向量的差向量的点积。
It depends on your definition of above and below, let me first talk about the easy case:
Ok, now the more difficult interpretation: On which side of the polygon is the point.
Unless it is complanar you cannot decide it for the polygon at once. So if it is non-complanar you have to tesselate it into triangles and decide for each of them.
For a triangle you can decide whether a point is above or below it (in 3D), first calculate the cross product of 2 vectors that make up the sides of the triangle; this will define a direction (= the definition of "above" and "below"), this depends on the order in which you use those 2 vectors so be careful. Then calculate the dot-product of the new vector (which is called the perpendicular of that triangle) and the difference-vector of the point-to-test and the triangle-base.