hdu1174-point to Straight line distance

Source: Internet
Author: User
Tags printf

A purely mathematical problem, figure out the distance between space and a space line

The point equation (x-x2)/a= (y-y2)/b= (Z-Z2)/c=tt, which describes the line which can be written out by the topic

then calculate the plane of the point perpendicular to the line, (A,B,C) is the normal vector of the plane, so A * (x-x1) +b* (y-y1) +c* (Z-Z1) =0

calculates the point where the space line intersects the plane A * (a*tt+x2-x1) +b* (b*tt+y2-y1) +c* (C*TT+Z2-Z1) =0

figure out tt= (A * (X1-X2) +b* (y1-y2) +c* (Z1-Z2))/(A*A+B*B+C*C) the intersection is (a*tt+x2,b*tt+y2,c*tt+z2 )

the distance between the intersection and the point given by the topic (that is, the head heart of the Bandit) is the distance. Then determine if the distance is less than the head radius of the headshot. Otherwise the head will not explode.

#include <iostream>
using namespace std;
int main () {
    int t;
    cin>>t;
    while (t--)
	{
        double h1,h2,x1,x2,y1,y2,z1,z2,a,b,c,r1,r2;
        Cin>>h1>>r1>>x1>>y1>>z1>>h2>>r2>>x2>>y2>>z2> >a>>b>>c;
        Z2+=H2*0.9-R2; Z2,Z1 is the height of the human foot, so to get the head heart height to add so much.
        z1+=h1-r1;
        Double Tt= (A * (X1-X2) +b* (y1-y2) +c* (Z1-Z2))/(A*A+B*B+C*C);
        Double x=a*tt+x2,y=b*tt+y2,z=c*tt+z2;
        if ((x-x1) * (x-x1) + (y-y1) * (y-y1) + (Z-Z1) * (Z-Z1) <=r1*r1) printf ("yes\n");
        else printf ("no\n");
    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.