Sicily 1907. Collision Detection

1907. Collision Detection

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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
// Problem#: 1907
// Submission#: 3590845
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>
#include <algorithm>
using namespace std;

struct Pt {
    int x, y, z;
};

bool operator < (Pt a, Pt b) {
    return a.x + a.y + a.z < b.x + b.y + b.z;
}

long long delta(int lower, int upper, int p) {
    if (p < lower) return lower - p;
    if (p > upper) return p - upper;
    return 0;
}

int main() {
    int cs;
    scanf("%d", &cs);
    while (cs--) {
        int xb, yb, zb, r;
        Pt v[8];
        for (int i = 0; i < 8; i++) scanf("%d%d%d", &v[i].x, &v[i].y, &v[i].z);
        scanf("%lld%lld%lld%lld", &xb, &yb, &zb, &r);
        sort(v, v + 8);
        long long dx = delta(v[0].x, v[7].x, xb);
        long long dy = delta(v[0].y, v[7].y, yb);
        long long dz = delta(v[0].z, v[7].z, zb);
        if (dx * dx + dy * dy + dz * dz <= (long long)r * r) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
    return 0;
}                                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值