《实时碰撞检测算法技术》读书笔记(九):球体与部分形体间的测试

球体与AABB间的测试

利用点至AABB的最近值,计算圆心距离AABB最近距离并与半径进行比较,若距离小于半径则相交。

计算最近平方距离

//Compute the square distance between a point and an AABB b

float SqDistPointAABB(Point p, AABB b)

{

    float sqDist = 0.0f;

    for(int i = 0; i < 3; i++) {

        //For each axis count any excess distance outside the box extents

        float v = p[i];

        if(v < b.min[i]) sqDist += (b.min[i] - v) * (b.min[i] - v);

        if(v > b.max[i]) sqDist += (v - b.max[i]) * (v - b.max[i]);

    }

    return sqDist;

}

在碰撞处理过程中,常要返回AABB上距离球心最近点,则可利用

//Given point p, return the point q on or in AABB b that is closest to p

void ClosestPtPointAABB(Point p, AABB b, Point &q) {

    .//For each coordinate axis, if the point coordinate value is

    //outside box, clamp it to the box, else keep it as is

    for(int i = 0; i < 3; i++) {

        float v = p[i];

        if(v < b.min[i]) v = b.min[i];    //v = max(v, b.min[i]);

        if(v > b.max[i]) v = b.max[i];    //v = min(v, b.max[i]);

        q[i] = v;

    }

}

球体与OBB间的测试

同球体与AABB测试原理,只是更改计算最近距离方法:

点与OBB最近点

//Given point p, return point q on (or in) OBB b, closest to p

void ClosestPtPointOBB(Point p, OBB b, Point &q)

{

    Vector d = p - b.c;

    //Start result at center of box; make steps from there

    q = b.c;

    //For each OBB axis...

    for(int i = 0; i < 3; i++) {

         //...project d onto that axis to get the distance

        //along the axis of d from the box center

        float dist = Dot(d, b.u[i]);

        //if distance farther than the box extents, clamp to the box

        if(dist > b.e[i]) dist = b.e[i];

        if(disr < -b.e[i]) dist = -b.e[i];

        //Step that distance along the axis to get world coordinate

        q += dist * b.u[i];

    }

}

点与OBB最近平方距离

//Compute the square distance between point p and OBB b

float SqDistPointOBB(Point p, OBB b)

{

    Point closest;

    ClosestPtPointOBB(p, b, closest);

    float sqDist = Dot(closest - p, closest - p);

    return sqDist;

}

球体与三角形间的测试

同理,求最近点以及最近距离并与半径比较:

//Return true if sphere s intersects triangle ABC,false otherwise.

//The point p on ac closest to the sphere center is also returned

int TestSphereeTriangle(Sphere s, Point a, Point b, Point c, Point &p)

{

    //Find point P on triangle ABC closest to sphere center

    p = ClosestPtPointTrangle(s.c, a, b, c);

    //Sphere and triangle intersect if the (squared) distance from sphere

    //center to point p is less than the (squared) sphere radius

    Vector v = p - s.c;

    return Dot(v, v) <= s.r*s.r;

}

球体与多边形间的测试

可以计算多边形上距离球心最近点并与球体半径进行对比。

已知一点P求多边形距其最近点可以采用以下方法:将多边形进行三角形划分并计算P距离三角形最近点,取其中最近的。该方法对于包含n个顶点的多边形需要进行n-2次三角形测试。

另外一种解决方案是:

1.测试球体是否与多边形所在平面相交,不相交则退出并返回false;

2.测试多边形中每一条边并考查是否穿越球体,穿越则退出并返回true;

3.将球心投影至多边形平面上。执行点-多边形包含测试并查看该点是否位于多边形内部。若是,则退出并返回true,否则退出并返回false。

内容简介  《实时碰撞检测算法技术》详细阐述了碰撞检测问题相关的高效解决方案及相应的数据结构和算法,主要包括:碰撞检测系统中的设计问题、数学和几何学入门、包围体、基本图元测试、层次包围体技术、空划分、BSP树层次结构、凸体算法、基于GPU的碰撞检测、数值健壮性、几何健壮性以及优化操作。另外,《实时碰撞检测算法技术》还提供了相应的算法、代码以及伪代码,以帮助读者进一步理解计算方案的实现过程。  《实时碰撞检测算法技术》适合作为高等院校计算机及相关专业的教材和教学参考书,也可作为相关开发人员的自学教材和参考手册。第1章 概述1.1 内容概览1.2 关于本书的代码第2章 碰撞检测系统中的设计问题2.1 碰撞算法的设计因素2.2 应用程序中对象的表达方式2.3 查询类型2.4 环境模拟参数2.5 性能2.6 健壮性2.7 实现使用的简洁性2.8 小结第3章 数学和几何学入门3.1 矩阵3.2 坐标系统和顶点3.3 向量3.4 质心坐标3.5 直线、光线和线段3.6 平面和半空3.7 多边形3.8 多面体3.9 凸包计算3.10 域3.11 Minkowski和Minkowski差3.12 小结第4章 包围体4.1 BV期望特征4.2 轴对齐包围盒4.3 Spheres球体4.4 方向包围盒4.5 扫掠体4.6 半空相交体4.7 其他类型的包围体4.8 小结第5章 基本图元测试5.1 最近点计算5.2 图元测试5.3 直线、光线和有向线段的相交测试5.4 其他类型的测试5.5 动态相交测试5.6 小结第6章 层次包围体技术6.1 层次结构设计问题6.2 层次结构的构建策略6.3 层次结构的遍历6.4 包围体层次结构示例6.5 合并包围体6.6 高效的树型表达方式及遍历6.7 通过缓存机制改善查询6.8 小结第7章 空划分第8章 BSP树层次结构第9章 凸体算法第10章 基于GPU的碰撞检测第11章 数值健壮性第12章 几何健壮性第13章 优化操作参考文献
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值