English 中文(简体)
2.D 2D空间物体无重叠的距离标签
原标题:
  • 时间:2009-05-24 11:35:13
  •  标签:

我需要给随机散布在屏幕上并保持移动的物体贴上文字标签。

贴标签的缺省立场和理想立场是所提及物体右侧。 我需要一种办法,以动态方式重新排列(或可能合并)标签,使其永远不会相互重叠或其他物体。

它们仍应尽可能接近目标,而且不应,只要物体本身顺利移动,就显示任何突然的“妇女运动”。

我不知道如何这样做,是否有算法来做这样的事情?

最佳回答

我用粗略的武力解决这一问题。

for each object as a
    for each colliding object as c
        if should_swallow(a, c)
            swallow(a, c)

由于物体在吞).其他物体时生长,因此不得不再次进行碰撞检查(新的重叠可能出现在中周期)。 然而,与Im一道工作的物体数量从未超过3个周期。

should子功能确定,它是否能够更好地根据大小、位置和以往防止浮油的发生情况,吞.物体或使其吞.。

问题回答

我建议使用物理学。 在标的上贴上标语,在每一标签上加固剂,以避免与其他物体(及其标签)相接近,排除所描述的物体。

Putting the label: You can figure out the tightest square which closes the objects and then drop a perpendicular from the right side of the square onto the object. Place the label at this point of intersection.

Detecting collision: Store the coordinates of the label and before you display the final buffer you can detect the collision of the labels using the coordinates.

Avoid sudden movements: This is the hard part because if you change the location of the labels only when collision is detected then there is going to be a jerk. The simple approach is to merge them when the collision is detected and for as long as a collision is there. The harder approach would be to move the labels. To make this smooth you will have to detect beforehand any collision that may appear some frames ahead and start moving your labels on some trajectory that would avoid any collision.





相关问题
热门标签