两个相交多边形之间的平滑过渡(有趣的问题)
我有一个有趣的问题,我已经尝试解决一段时间了。对此没有“正确”的解决方案,因为没有严格的成功标准。我想要完成的是两个简单多边形之间的平滑过渡,从多边形 A 到多边形 B。多边形 A 完全包含在多边形 B 内。
我对这种过渡的标准是:
- 过渡在时间和空间上是连续的
- 。从多边形 A 到多边形 B 的“填充”应该被填充,就好像 A 中的液体正在倒入 B 的形状一样
- 重要的是,该动画可以动态计算,也可以由集合定义需要很少空间的参数,比如说少于几个KB。
作弊是完全可以的,任何解决这个问题并使其看起来不错的方法都是可能的解决方案。
我考虑过但大多被排除的解决方案:
- 将 A 和 B 中的顶点配对并简单地进行插值。看起来不太好,并且在凹多边形的情况下不起作用。
- 将区域 BA 划分为凸多边形(可能是 Voronoi 图),并通过对较小的凸多边形执行 BFS 来计算多边形的离散状态。然后我在离散状态之间进行插值。注意:如果多边形 BA 是凸多边形,则过渡相当简单。我没有采用这个解决方案,因为将 BA 划分为大小相等的小凸多边形非常困难
- 模拟:细分多边形 A。以离散但小的步骤沿多边形线法线(向外)移动每个顶点。对于每一步,检查顶点是否仍在 B 内部。如果不是,则移回之前的位置。重复直到 A 等于 B。我不喜欢这个解决方案,因为检查顶点是否在多边形内部的速度很慢。
大家有什么不同的想法吗?
I have an interesting problem that I've been trying to solve for a while. There is no "right" solution to this, as there is no strict criteria for success. What I want to accomplish is a smooth transition between two simple polygons, from polygon A to polygon B. Polygon A is completely contained within polygon B.
My criteria for this transition are:
- The transition is continuous in time and space
- The area that is being "filled" from polygon A into polygon B should be filled in as if there was a liquid in A that was pouring out into the shape of B
- It is important that this animation can be calculated either on the fly, or be defined by a set of parameters that require little space, say less than a few Kb.
Cheating is perfectly fine, any way to solve this so that it looks good is a possible solution.
Solutions I've considered, and mostly ruled out:
- Pairing up vertices in A and B and simply interpolate. Will not look good and does not work in the case of concave polygons.
- Dividing the area B-A into convex polygons, perhaps a Voronoi diagram, and calculate the discrete states of the polygon by doing a BFS on the smaller convex polygons. Then I interpolate between the discrete states. Note: If polygon B-A is convex, the transition is fairly trivial. I didn't go with this solution because dividing B-A into equally sized small convex polygons was surprisingly difficult
- Simulation: Subdivide polygon A. Move each vertex along the polygon line normal (outwards) in discrete but small steps. For each step, check if vertex is still inside B. If not, then move back to previous position. Repeat until A equals B. I don't like this solution because the check to see whether a vertex is inside a polygon is slow.
Does anybody have any different ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想保持简单且快速,您可以继续您的最后一个想法,即考虑缩放多边形 A,使其逐渐填充多边形 B。您不必检查向外缩放的顶点是否仍在内部多边形 B。根据您的代码环境和 API 的情况,您可以使用多边形 B 的轮廓来掩盖扩展多边形 A 的像素。
在现代 OpenGL 中,您可以在片段着色器中执行此操作。您必须将多边形 B 渲染到纹理,将该纹理发送到着色器,然后使用该纹理查找当前渲染的片段是否映射到多边形 B 设置的纹理值。如果不是,该片段被丢弃。您需要使纹理与屏幕一样大。如果没有,您需要在着色器中包含一些相机计算,以便您可以将要测试的片段“渲染”到纹理中,就像将多边形 B 渲染到该纹理中一样。
If you want to keep this simple and somewhat fast, you could go ahead with your last idea where you consider scaling polygon A so that it gradually fills polygon B. You don't necessarily have to check if the scaled-outward vertices are still inside polygon B. Depending on what your code environment and API is like, you could mask the pixels of the expanding polygon A with the outline of polygon B.
In modern OpenGL, you could do this inside a fragment shader. You would have to render polygon B to a texture, send that texture to the shader, and then use that texture to look up if the current fragment being rendered maps to a texture value that has been set by polygon B. If it is not, the fragment gets discarded. You would need to have the texture be as large as the screen. If not, you would need to include some camera calculations in your shaders so you can "render" the fragment-to-test into the texture in the same way you rendered polygon B into that texture.