# hdoj 2436 Collision Detection

Posted by 111qqz on Friday, July 31, 2015

# Collision Detection

**Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1207    Accepted Submission(s): 367
**

Problem 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

Source

2008 Asia Chengdu Regional Contest Online

Recommend

lcy   |   We have carefully selected several similar problems for you:  2437 2429 2433 2435 2428

``````/*************************************************************************
> File Name: code/2015summer/#6/II.cpp
> Author: 111qqz
> Email: rkz2013@126.com
> Created Time: 2015年08月01日 星期六 03时09分18秒
************************************************************************/

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<stack>
#define y0 abc111qqz
#define y1 hust111qqz
#define yn hez111qqz
#define j1 cute111qqz
#define tm crazy111qqz
#define lr dying111qqz
using namespace std;
#define REP(i, n) for (int i=0;i<int(n);++i)
typedef long long LL;
typedef unsigned long long ULL;
const int inf = 0x7fffffff;

LL dis(LL x1,LL x2,LL y1,LL y2,LL z1,LL z2)
{

return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);

}
int main()
{
int T;                 //整体算法是寻找距离球最近的点，比较这个点到球心的距离和半径
// 卧槽，读错题了，长方体是实心的啊喂！怪不得我想的那么麻烦！
cin>>T;
while (T--)
{
LL tx,ty,tz;
LL x1 = inf;
LL x2 = -inf;
LL y1 = inf;
LL y2 = -inf;
LL z1 = inf;
LL z2 = -inf;
for ( int i = 1 ; i <= 8 ; i++ )
{

scanf("%lld %lld %lld",&tx,&ty,&tz);
x1 = min(tx,x1);
x2 = max(tx,x2);
y1 = min(ty,y1);
y2 = max(ty,y2);
z1 = min(tz,z1);
z2 = max(tz,z2);
}
LL bx,by,bz,r;
LL x,y,z;
scanf("%lld %lld %lld %lld",&bx,&by,&bz,&r);
x = bx;
y = by;
z = bz;
if (x>x2) x=x2;
if (x<x1) x=x1;
if (y>y2) y=y2;
if (y<y1) y=y1;
if (z>z2) z=z2;
if (z<z1) z=z1;
if (r*r>=dis(x,bx,y,by,z,bz))
{
puts("Yes");
}
else
{
puts("No");
}

}

return 0;
}
``````

「真诚赞赏，手留余香」