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 Description
Due 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-dimensional 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.

 
Input
The 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-dimensional line with infinite length.

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

 
Output
For 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 should be round to 6 digits after decimal point. Test cases guarantee the uniqueness of the best Time Tunnel.

 
Sample Input
1
1 0 1 0 1 1 0 0 0 1 1 1
 
Sample Output
0.408248
0.500000 0.500000 1.000000 0.666667 0.666667 0.666667
 
Source

有必要拿出空间解析几何出来看看了,尼玛用平面方程跟直线方程求解的时候除数为零了。最后没办法只能看大神的模版了。。。。

大概解题思路:先求出两直线的公垂线(两方向向量的叉积),以公垂线跟一直线形成一平面求另一直线与该平面的交点。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std; const double eps = 1e-;
struct Point3//三维空间点
{
double x, y, z;
Point3(double x=,double y=,double z=): 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//空间直线
{
Point3 a,b;
};
struct Plane//空间平面
{
Point3 a,b,c;
Plane(){}
Plane(Point3 a, Point3 b, Point3 c):a(a),b(b),c(c){}
};
int dcmp(double x)
{
if(fabs(x) < eps) return ;
return x < ? - : ;
}
double Dot(Vector3 A,Vector3 B) { return A.x*B.x + A.y*B.y + A.z*B.z; }
double Length2(Vector3 A) { return Dot(A, A); }
Vector3 Cross(Vector3 A, Vector3 B) { return Vector3(A.y*B.z - A.z*B.y, A.z*B.x - A.x*B.z, A.x*B.y - A.y*B.x); } double LineToLine(Line u,Line v,Vector3 &t)//空间直线间距离
{
t=Cross(u.a-u.b,v.a-v.b);
return fabs(Dot(u.a-v.a,t))/sqrt(Length2(t));
} Vector3 normalVector(Plane s)//取平面法向量
{
return Cross(s.a-s.b,s.b-s.c);
} Point3 Intersection(Line l,Plane s)//空间平面与直线的交点
{
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.a,A.b,A.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%lf%lf", &A.a.x, &A.a.y, &A.a.z);
scanf("%lf%lf%lf", &A.b.x, &A.b.y, &A.b.z);
scanf("%lf%lf%lf", &B.a.x, &B.a.y, &B.a.z);
scanf("%lf%lf%lf", &B.b.x, &B.b.y, &B.b.z);
solve(A,B);
}
return ;
}

hdu 4741 Save Labman No.004异面直线间的距离既构成最小距离的两个端点的更多相关文章

  1. hdu 4741 Save Labman No.004 (异面直线的距离)

    转载学习: #include <cstdio> #include <cstdlib> #include <cstring> #include <algorit ...

  2. HDU 4741 Save Labman No.004 (2013杭州网络赛1004题,求三维空间异面直线的距离及最近点)

    Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )

    空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...

  4. HDU 4741 Save Labman No.004 2013 ACM/ICPC 杭州网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4741 题意:给你两条异面直线,然你求着两条直线的最短距离,并求出这条中垂线与两直线的交点. 需要注意的是 ...

  5. HDU 4741 Save Labman No.004(计算几何)

    题目链接 抄的模版...mark一下. #include <iostream> #include <cstring> #include <cstdio> #incl ...

  6. hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]

    // Time 234 ms; Memory 244 K #include<iostream> #include<cstdio> #include<cmath> u ...

  7. hdu 4741 Save Labman No.004(2013杭州网络赛)

    http://blog.sina.com.cn/s/blog_a401a1ea0101ij9z.html 空间两直线上最近点对. 这个博客上给出了很好的点法式公式了...其实没有那么多的tricky. ...

  8. [HDU 4741]Save Labman No.004[计算几何][精度]

    题意: 求两条空间直线的距离,以及对应那条距离线段的两端点坐标. 思路: 有一个参数方程算最短距离的公式, 代入求即可. 但是这题卡精度... 用另外的公式(先算出a直线上到b最近的点p的坐标, 再算 ...

  9. HDU 4741 Save Labman No.004 (几何)

    题意:求空间两线的最短距离和最短线的交点 题解: 线性代数和空间几何,主要是用叉积,点积,几何. 知道两个方向向量s1,s2,求叉积可以得出他们的公共垂直向量,然后公共垂直向量gamma和两线上的点形 ...

随机推荐

  1. js类型判别大合集

    1.typeof number,string,boolean,undefined,symbol,object,function 对象中除了函数为function,其他对象都判别为object, 缺陷: ...

  2. 二叉树、二叉搜索树、平衡二叉树、B树、B+树的精确定义和区别探究

    概述 关于树的概念很多,B树,B+树,红黑树等等. 但是你去翻翻百度百科,或者用百度或者谷歌搜索一下中文的树结构的介绍,全都是狗屁.没有哪个中文网站是真正精确解释树的定义的,尤其是百度百科. 下面我要 ...

  3. tomcat - 自带日志的区分

    在tomcat 中,logs文件夹下会存放着一些tomcat自带的日志文件,其中有三种文件: 1 > localhost_access_log.2017-12-28 文件,它用来记录tomcat ...

  4. C#:CodeSmith根据数据库中的表创建C#数据模型Model + 因为没有钱买正版,所以附加自己写的小代码

    对于C#面向对象的思想,我们习惯于将数据库中的表创建对应的数据模型: 但假如数据表很多时,我们手动增加模型类会显得很浪费时间: 这个时候有些人会用微软提供的EntityFrameWork,这个框架很强 ...

  5. 深入理解 hashcode 和 hash 算法

    深入理解 hashcode 和 hash 算法 2017年12月30日 23:06:07 阅读数:5197 标签: hashhashmaphashcode二进制 更多 个人分类: jdk-源码  ht ...

  6. shell 练习题 - 第三周

    1.编写脚本/root/bin/backup.sh,可实现每日将/etc/目录备份到 /root/etcYYYY-mm-dd中 #!/bin/bash echo "start backup& ...

  7. CentOS 7 忘记root密码解决方法

    CentOS 7  root密码的重置方式和CentOS 6完全不一样,CentOS 7与之前的版本6变化还是比较大的,以进入单用户模式修改root密码为例: 1.重启机器,进入grub菜单的时候按e ...

  8. 【android】签署应用采用相同证书的用处

    在应用的预期生命周期内,您应使用相同证书签署所有 APK 应用升级:当系统安装应用的更新时,它会比较新版本和现有版本中的证书.如果证书匹配,则系统允许更新.如果您使用不同的证书签署新版本,则必须为应用 ...

  9. Python PycURL的安装使用

    PycURL中文简介:https://blog.csdn.net/qq_41185868/article/details/80487014 PycURL英文简介(如下):http://pycurl.i ...

  10. LeetCode(147) Insertion Sort List

    题目 Sort a linked list using insertion sort. 分析 实现链表的插入排序 注意: 程序入口的特殊输入判断处理! 节点的链接处理,避免出现断链! AC代码 /** ...