Minkowski sums and differences闵可夫斯基和与差

Minkowski sums and differences

There are many ways to do collision detection, but a fairly general one is Minkowski differences. The idea is that you do a binary operation on two shapes to get a new shape, and if the origin (the zero vector) is inside that shape, then they are colliding. The minkowski sum lets you define some interesting shapes that are both easy to draw and easy to do collision detection on.

The Minkowski sum
What does it mean to add shapes?

One representation of a shape is a (possibly infinite) set of points. so, a point is just a set with one element, and a circle is the set在这里插入图片描述 { v | || v - c || <=r}, or the set of all points within radius r of a centre point c.

The minkowski sum of A and B is the set of all points that are the sum of any point in A and B. The formula is:
在这里插入图片描述

Some examples
To instill you with intuition of what a minkowski sum looks like, here are a few examples:

The sum of any shape and a point is that shape translated by that point.

The sum of any shape and two points is two translated (possibly overlapping) copies of that shape.

The sum of two circles is a larger circle (sum the radii) with its centre at the sum of the centres of the smaller circles.

The sum of any shape and a line is that shape swept through that line. Think of placing your shape in sand, and dragging it along the line.

Similarly, the sum of a shape and any curve is what you’d get by sweeping the shape through the curve.

The sum of two parallel lines is a longer line.

For perpendicular lines, you get a square.

Minkowski difference
The minkowski difference is what you get by taking the minkowski sum of a shape and the mirror of another shape. So, your second shape gets flipped about the origin (all of its points are negated).

在这里插入图片描述

And if we ask “are these objects colliding?”, we’re really asking if they have any points in common. If they do have a point p in common, then p - p = 0 must be in the Minkowski difference. If they do not share a point, then a - b is never 0, because a 不等于 b. So, we have reduced the collision detection problem to a Minkowski sum problem.

### 使用 Minkowski 进行碰撞检测 #### 基本原理 Minkowski 是一种几何运算方法,用于描述两个集合 \( A \) \( B \) 的组合。其定义为: \[ A \oplus B = \{ a + b : a \in A, b \in B \} \] 在碰撞检测中,通常会利用 Minkowski 来简化问题。对于两物体是否相交的判断,可以通过检查 Minkowski 的结果集中是否存在原点来进行判定[^1]。 具体来说,在 GJK(Gilbert–Johnson–Keerthi)算法中,通过支持函数(support function),可以在不显式计算整个 Minkowski 的情况下逐步逼近目标区域,并最终验证该区域内是否包含原点[^3]。 #### 实现过程 以下是基于上述理论的一个典型实现框架: ```python def gjk_algorithm(support_function_A, support_function_B): """ 判断两个对象是否有重叠。 参数: support_function_A: 物体A的支持函数 support_function_B: 物体B的支持函数 返回: bool: 如果有重叠返回True,否则False """ def get_support(direction): """获取方向上最远点""" return support_function_A(-direction) - support_function_B(direction) simplex = [] # 初始化单纯形列表 origin = np.array([0., 0.]) # 定义原点 initial_direction = np.array([1., 0.]) new_point = get_support(initial_direction) if np.dot(new_point, initial_direction) <= 0: return False # 方向错误,则无解 simplex.append(new_point) while True: search_direction = None if len(simplex) == 1: search_direction = -simplex[0] elif len(simplex) == 2: edge_vector = simplex[1] - simplex[0] perpendicular = np.array([-edge_vector[1], edge_vector[0]]) if np.dot(origin - simplex[0], perpendicular) > 0: search_direction = perpendicular else: search_direction = -perpendicular elif len(simplex) >= 3: result = is_simplex_contains_origin(simplex, origin) if result == 'contains': return True elif result == 'reduce': reduce_simplex() continue else: break new_point = get_support(search_direction) if np.dot(new_point, search_direction) < 0: return False # 新点不在期望的方向上 simplex.append(new_point) return False def is_simplex_contains_origin(simplex, origin): """判断单纯形是否包含原点""" pass # 需要根据具体情况实现此逻辑 def reduce_simplex(): """减少单纯形规模""" pass # 同样需依据实际需求编写相应代码 ``` 以上伪代码展示了如何运用支持函数以及不断调整搜索路径直至找到可能覆盖原点的情况或者确认无法达到为止的过程[^2]。 #### 应用场景分析 这种方法特别适合于处理具有复杂边界条件的对象之间的交互情况。例如机器人运动规划领域内的障碍物规避问题或是视频游戏中角色间物理行为模拟等方面均能见到它的身影[^4]。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值