HDU 4741 save labman No. 004 The distance between two different-plane straight lines constitutes the minimum distance of the two endpoints

Source: Internet
Author: User
Tags float number
Save labman No. 004

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1473 accepted submission (s): 484


Problem descriptiondue to the preeminent research conducted by Dr. kyouma, human beings have a breakthrough in the understanding of time and universe. according to the research, the universe in common sense is not the only one. multi world line is running simultaneously. in simplicity, let us use a straight line in Three-dimen1_coordinate system to indicate a single world line.

During the research in world line Alpha, the assistant of dr. kyouma, also the labman No. 004, Christina dies. dr. kyouma wants to save his assistant. thus, he has to build a time tunnel to jump from world line Alpha to world line beta in which Christina can be saved. more specifically, a time tunnel is a line connecting world line Alpha and world line beta. in order to minimizing the risks, dr. kyouma wants you, labman No. 003 to build a time tunnel with shortest length.

 

Inputthe first line contains an integer T, indicating the number of test cases.

Each case contains only one line with 12 float numbers (x1, Y1, Z1), (X2, Y2, Z2), (X3, Y3, Z3), (X4, Y4, z4), correspondingly indicating two points in world line Alpha and world line beta. note that a world line is a three-dimen1_line with infinite length.

Data satisfy T <= 10000, | x, y, z | <= 10,000.

 

Outputfor each test case, please print two lines.

The first line contains one float number, indicating the length of best time tunnel.

The second line contains 6 float numbers (XA, ya, za), (XB, Yb, ZB), seperated by blank, correspondingly indicating the endpoints of the best time tunnel in world line Alpha and world line beta.

All the output float number shocould be round to 6 digits after decimal point. Test Cases guarantee the uniqueness of the best time tunnel.

 

Sample input11 0 1 0 1 1 0 0 0 1 1 1

 

Sample output0.4011680.500000 0.500000 1.000000 0.666667 0.666667 0.666667

 

Source2013 ACM/ICPC Asia Regional Hangzhou online

 

It is necessary to take out the spatial analytic ry and look at it. Nima used the plane equation and the linear equation to solve the divisor zero. In the end, there is no way to look at the templates of great gods ....

General Solution: first obtain the vertical line of two straight lines (the cross product of the Two-Direction vector), take the vertical line and the linear line into a plane to find the intersection of the other always line and the plane.

# Include <iostream> # include <cstring> # include <cstdio> # include <cmath> using namespace STD; const double EPS = 1e-8; struct point3 // three-dimensional space point {Double X, Y, Z; point3 (double x = 0, Double Y = 0, Double Z = 0): x (x ), Y (Y), Z (z) {} point3 operator + (point3 & T) {return point3 (x + T. x, Y + T. y, Z + T. z);} point3 operator-(point3 & T) {return point3 (x-t.x, y-t.y, z-t.z);} point3 operator * (Double P) {return point3 (x * P, y * P, Z * P);} point3 operator/(Double P) {return point3 (x/P, Y/P, Z/P) ;}}; typedef point3 vector3; struct line // Spatial Straight Line {point3 A, B ;}; struct plane // spatial plane {point3 A, B, C; plane () {} plane (point3, point3 B, point3 C): A (a), B (B), C (c) {}}; int DCMP (Double X) {If (FABS (X) <EPS) return 0; return x <0? -1: 1;} double dot (vector3 A, vector3 B) {return. x * B. X +. y * B. Y +. z * B. z;} double leng2( vector3 A) {return dot (a, a);} vector3 cross (vector3 A, vector3 B) {return vector3 (. y * B. z-. z * B. y,. z * B. x-. x * B. z,. x * B. y-. y * B. x);} double linetoline (line U, line V, vector3 & T) // distance between spatial straight lines {T = cross (U. a-u. B, V. a-v. B); Return FABS (dot (U. a-v.a, t)/SQRT (length1 (t);} vector3 normalvector (plane s) // take the flat method vector {return cross (S. a-s. B, S. b-s.c);} point3 intersection (line L, plane s) // intersection of the spatial plane and the line {point3 ret = normalvector (s); Double T = (Ret. x * (S. a. x-l.a.x) + ret. y * (S. a. y-l.a.y) + ret. z * (S. a. z-l.a.z)/(Ret. x * (L. b. x-l.a.x) + ret. y * (L. b. y-l.a.y) + ret. z * (L. b. z-l.a.z); ret. X = L. a. X + (L. b. x-L. a. x) * t; ret. y = L. a. Y + (L. b. y-L. a. y) * t; ret. z = L. a. Z + (L. b. z-L. a. z) * t; return ret;} void solve (line A, line B) {vector3 normal; double D = linetoline (a, B, normal); printf ("%. 6lf \ n ", d); plane Pa = plane (. a,. b,. A + normal); plane Pb = plane (B. a, B. b, B. A + normal); point3 u = intersection (B, PA); point3 v = intersection (A, Pb); printf ("%. 6lf %. 6lf %. 6lf %. 6lf %. 6lf %. 6lf \ n ", V. x, V. y, V. z, U. x, u. y, U. z);} int main () {int t; scanf ("% d", & T); While (t --) {Line A, B; scanf ("% lf", &. a. x, &. a. y, &. a. z); scanf ("% lf", &. b. x, &. b. y, &. b. z); scanf ("% lf", & B. a. x, & B. a. y, & B. a. z); scanf ("% lf", & B. b. x, & B. b. y, & B. b. z); solve (a, B);} 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.