# Collision Detection

Description

In physical simulations, video games and computational geometry, collision detection involves algorithms for checking for collision, i.e. intersection, of two given objects. Collision detection algorithms are a basic component of 3D video games. Without them, characters could go through walls and other obstacles.
Here comes an interesting problem, given a ball and a cuboid, you need to detect whether they collide. We say that two objects collide if and only if they share at least one point.

Input

The first line of input is the number of test cases.
Each test case contains two lines, the first line contains 24 integers X1, Y1, Z1, …, X8, Y8, Z8, representing the 8 vertexes of the cuboid. Vertexes are given in random order and you can make sure that all edges of the cuboid are parallel to coordinate axes; the second line contains 4 integers X,Y,Z,R representing the central point of the ball and its radius. All integers given are non-negative and will be less than 100000.

Output

For each case output "Yes" Or "No" on a single line.

Sample Input

2 0 0 0 0 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 1 2 2 2 2 0 0 0 0 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 1 2 2 2 1

Sample Output

Yes No

#include<iostream> #include<algorithm> using namespace std; const int INF = 1 << 30; struct Point { int x, y, z; } P[8]; struct Ball { int x, y, z, r; } B; int maxx, maxy, maxz, minx, miny, minz; inline void rebuild() { maxx = maxy = maxz = -INF; minx = miny = minz = INF; for(int i = 0; i < 8; i++) { maxx = max(P[i].x, maxx); maxy = max(P[i].y, maxy); maxz = max(P[i].z, maxz); minx = min(P[i].x, minx); miny = min(P[i].y, miny); minz = min(P[i].z, minz); } } //intersect in every aspect inline bool judge() { long long dx = 0; long long dy = 0; long long dz = 0; long long R = (long long)B.r * B.r; if(maxx >= B.x && minx <= B.x) dx = 0; else dx = min((long long)(maxx - B.x) * (maxx - B.x), (long long)(minx - B.x) * (minx - B.x)); if(maxy >= B.y && miny <= B.y) dy = 0; else dy = min((long long)(maxy - B.y) * (maxy - B.y), (long long)(miny - B.y) * (miny - B.y)); if(maxz >= B.z && minz <= B.z) dz = 0; else dz = min((long long)(maxz - B.z) * (maxz - B.z), (long long)(minz - B.z) * (minz - B.z)); return dx + dy + dz <= R; } int main() { int T; cin>>T; while( T-- ) { for(int i = 0; i < 8; i++) cin>>P[i].x>>P[i].y>>P[i].z; cin>>B.x>>B.y>>B.z>>B.r; rebuild(); if(judge()) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }

#### Real Time Collision Detection

2017-02-10 14:00:16

#### Unity-Rigidbody【刚体】组件-Collision Detection碰撞检测模式

2017-09-10 15:32:03

#### 【计算几何】 HDOJ 2436 Collision Detection

2015-02-13 19:50:17

#### good----Real-Time Collision Detection

2018年04月16日 4.34MB 下载

#### 关于Unity中刚体组件Collision Detection碰撞检测属性的结果分析

2018-04-11 11:22:05

#### 实时碰撞检测算法技术 real time collision detection

2012年05月11日 40.84MB 下载

#### Real-Time Rendering (9) - 碰撞检测（Collision Detection）

2013-12-25 21:12:48

#### hdoj 2436 Collision Detection（数学型计算几何）

2012-02-29 01:02:21

#### 基于层的碰撞检测 Layer-Based Collision Detection

2014-10-22 14:20:06

#### Real Time Collision Detection Source Code

2009年10月18日 53KB 下载