The Tower HDU - 6559 (analytic geometry)

The Tower

HDU - 6559

The Tower shows a tall tower perched on the top of a rocky mountain. Lightning strikes, setting the building alight, and two people leap from the windows, head first and arms outstretched. It is a scene of chaos and destruction.*

There is a cone tower with base center at (0, 0, 0), base radius r and apex (0, 0, h). At time 0 , a point located at (x0x0, y0y0, z0z0) with velocity (vxvx, vyvy, vzvz). What time will they collide? Here is the cone tower.
img

Input

The first line contains testcase number TT (TT ≤ 1000), For each testcase the first line contains spaceseparated real numbers rr and hh (1 ≤ rr, hh ≤ 1000) — the base radius and the cone height correspondingly.
For each testcase the second line contains three real numbers x0x0, y0y0, z0z0 (0 ≤ |x0x0|, |y0y0|, z0z0 ≤ 1000). For each testcase the third line contains three real numbers vxvx, vyvy, vzvz (1 ≤ v2xvx2 + v2yvy2 + v2zvz2 ≤ 3 × 106106). It is guaranteed that at time 0 the point is outside the cone and they will always collide.

Output

For each testcase print Case ii : and then print the answer in one line, with absolute or relative error not exceeding 10−610−6

Sample Input

2
1 2
1 1 1
-1.5 -1.5 -0.5
1 1
1 1 1
-1 -1 -1

Sample Output

Case 1: 0.3855293381
Case 2: 0.5857864376

Meaning of the questions: in three-dimensional space, give you a bottom surface of the cone surface XOY bottom center of the circle at the origin. Gave a given fixed point of the initial coordinates and velocity component in the axial direction of his three coordinates, fixed point is calculated when impinging cone.

Thoughts: We set the impact time t, we can obtain the coordinates of t (x, y, z) according to the speed of the three directions and because the conical surface met

So this can be obtained cross-sectional view in FIG nowr, i.e., according to a x ^ 2 + y ^ 2 = nowr ^ 2 can draw a quadratic equation in t and solving to determine which qualified root, and that the output of a small can.

Specific equations can see the group Friends of the formula:
Juju's blog connection: https://www.cnblogs.com/Dillonh/p/11196418.html

In fact, the smaller the output directly to the root of the equation is the answer, specifically why I still do not know.

See details Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2) { ans = ans * a % MOD; } a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int *p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
typedef long double ld;
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    int t;
    gbtb;
    cin >> t;
    ld x, y, z, r, h, vx, vy, vz;
    repd(cas, 1, t) {
        cin >> r >> h;
        cin >> x >> y >> z;
        cin >> vx >> vy >> vz;
        ld a = (vx * vx + vy * vy - r * r * vz * vz / h / h);
        ld b = (2.0 * x * vx + 2.0 * y * vy - r * r * (2.0 * z * vz - 2.0 * h * vz) / h / h);
        ld c = x * x + y * y - r * r * (h * h + z * z - 2.0 * h * z) / h / h;
        ld g1 = -b - sqrt(b * b - 4.0 * a * c);
        g1 /= 2.0 * a;
        cout << "Case " << cas << ": ";
        cout << fixed << setprecision(7) << g1 << endl;
    }
    return 0;
}

inline void getInt(int *p)
{
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    } else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Guess you like

Origin www.cnblogs.com/qieqiemin/p/11461567.html