使用四边形的重心坐标
你们中的一些人知道如何使用重心填充二维四边形 坐标?目前,我将四边形分成2个三角形, 但这种方式效率低下,因为我必须迭代第二个 边界框重复先前填充的像素(通过 例如,为了填充第二个三角形,我遍历了第一个三角形 属于由第二个三角形形成的边界框) 谢谢埃斯米特
some of you know how fill a quads in 2D using barycentric
coordinates?At the present, I'm splitting the quads into 2 triangles,
but that way is inefficient because I have to iterate over the second
bounding box which repeats pixel that were filled previously (by
example, to fill the 2nd triangle I traversed the 1st triangle that
belongs at bounding box formed by 2nd triangle)
Thanks
esmitt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个 python 示例,应该就是您正在寻找的。您可能知道,二维四边形没有唯一定义的重心坐标(三维四面体有重心坐标,但这是另一回事)。
基本上我正在计算每个边缘的线系数,然后检查该点是否位于每个边缘的正确一侧。线系数未标准化,因为如果您只想进行命中/未命中测试,则不需要(您将仅检查符号,而不检查 xnx + yny + nk 的大小)。
请注意,这种方法需要凸向四边形......
Here is a python example that should be what you're looking for. As you probably know there are no uniquely defined barycentric coordinates for quads in two dimension (there are barycentric coordinates for tetrahedra in three dimensions, but that's another thing).
Basically I'm computing the line coefficients for every edge and then check if the point is on the correct side of each of them. The line coefficients are not normalized because if you only want an hit/miss test that is not needed (you will only check the sign and not the magnitude of xnx + yny + nk).
Note that this approach requires convex oriented quads ...