GDC 2010 Session:Physics for Programmers,Erin Catto:Computing Distance,pdf
Erin Catto是二维物理库Box2D的开发者
内容:1)点和基本形状的距离计算;2)点和复杂几何体的距离计算(GJK);3)复杂几何体之间的距离计算
2D世界中距离的计算的几个重要的点:
- 点-线段、点-三角形的距离计算依赖于:barycentric coordinate ,Voronoi region;
- 点-多边形的距离计算依赖于点-线段和点-三角形
- 多边形-多边形的距离计算可退化为点-多边形的距离计算
点-线段、点-三角形
点的重心坐标(barycentric coordinate)是线段或三角形顶点对该点的影响权重,计算出点-线段、点-三角形的barycentric coordinate
计算三角形的重心坐标:
平面上的所有点对线段、三角形的barycentric coordinate的值定义了线段、三角形的voronoi regions;
线段的voronoi region:
三角形的voronoi region:
用点的barycentric coordinate获得voronoi region,并获得与该点距离最短的顶点、边并判断是否在形内,从而获得线段或三角形上距离点的最近点,并计算距离
// closest point algorithm
input: A, B, C, Q
compute uAB, vAB, uBC, vBC, uCA, vCA
compute uABC, vABC, wABC
// Test vertex regions …
// Region A
if (vAB <= 0 && uCA <= 0)
return A
// Similar tests for Region B and C
// Test edge regions …
// Region AB
if (uAB > 0 && vAB > 0 && wABC <= 0)
return uAB * A + vAB * B
// Similar for Regions BC and C
// Else interior region ABC
assert(uABC > 0 && vABC > 0 && wABC > 0)
return Q
点-convex
simplex:
计算点-convex的距离即是找到最近的simplex(二维空间中即点、线段或三角形)上的最近点
GJK算法用于找到convex多边形上的最近点,由Gilbert, Johnson, and Keerthi共同发明;算法思路是不断找到当前simplex上的最近点,并根据search direction找到support point,使用support point构造更优的simplex
support point:给出点集和方向,在这个方向上最远的点是这个点集的support point
GJK算法伪代码
Input: polygon and point Q
pick arbitrary initial simplex S
loop
compute closest point P on S
cull non-contributing vertices from S
build vector d pointing from P to Q
add support point to S
end
点-non convex
由于non convex顶点永远不会成为support point(任意方向上都有更远的点),。。。
convex-convex
GJK算法可以计算点-convex,可以通过将convex-convex转化为点-convex来计算
闵可夫斯基差(Minkowski difference):
convex X和convex Y的minkowski difference的convex hull Z有两个特殊性质:
性质1:X-Y的距离等于原点O-Z的距离
性质2:Z在d方向上的support point永远来自于X、Y分别在-d、d方向上support point的差
计算X-Y的距离过程中,不需要真正将Minkowski difference的convex hull Z计算出来,只需要修改计算support point的函数即可
本文介绍了Box2D库中2D物理世界中距离计算的方法,包括点与基本形状、点与复杂几何体以及复杂几何体之间的距离计算。重点讲解了点的重心坐标、Voronoi区域以及GJK算法在解决这些问题中的应用。
5023

被折叠的 条评论
为什么被折叠?



