http://blog.sina.com.cn/s/blog_a401a1ea0101ij9z.html

空间两直线上最近点对。

这个博客上给出了很好的点法式公式了。。。其实没有那么多的tricky。。。不知到别人怎么错的。。。

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<sstream>
#include<vector>
#include<string>
#include<cstdio>
#include<bitset>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define MP make_pair
#define eps 1e-10
using namespace std; struct Point
{
double x, y, z;
Point(double x=0, double y=0, double z=0) : x(x), y(y),z(z){}
};
typedef Point Vector; Vector operator + (Vector a, Vector b) { return Vector(a.x+b.x, a.y+b.y, a.z+b.z); };
Vector operator - (Vector a, Vector b) { return Vector(a.x-b.x, a.y-b.y, a.z-b.z); };
Vector operator * (Vector a, double p) { return Vector(a.x*p, a.y*p, a.z*p); }
Vector operator / (Vector a, double p) { return Vector(a.x/p, a.y/p, a.z/p); } double Dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
double Length(Vector a) { return sqrt(Dot(a, a)); }
Vector Cross(Point a, Point b)
{
return Vector(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x);
} Point a1, b1, a2, b2;
int main()
{
int n;
scanf("%d", &n);
while(n--)
{
scanf("%lf%lf%lf", &a1.x, &a1.y, &a1.z);
scanf("%lf%lf%lf", &b1.x, &b1.y, &b1.z);
scanf("%lf%lf%lf", &a2.x, &a2.y, &a2.z);
scanf("%lf%lf%lf", &b2.x, &b2.y, &b2.z);
Vector v1 = (a1-b1), v2 = (a2-b2);
Vector N = Cross(v1, v2);
Vector ab = (a1-a2);
double ans = Dot(N, ab) / Length(N);
Point p1 = a1, p2 = a2;
Vector d1 = b1-a1, d2 = b2-a2;
Point ans1, ans2;
double t1, t2;
t1 = Dot((Cross(p2-p1, d2)), Cross(d1, d2));
t2 = Dot((Cross(p2-p1, d1)), Cross(d1, d2));
double dd = Length((Cross(d1, d2)));
t1 /= dd*dd;
t2 /= dd*dd;
ans1 = (a1 + (b1-a1)*t1);
ans2 = (a2 + (b2-a2)*t2);
printf("%.6f\n", fabs(ans));
printf("%.6f %.6f %.6f ", ans1.x, ans1.y, ans1.z);
printf("%.6f %.6f %.6f\n", ans2.x, ans2.y, ans2.z);
}
return 0;
}

hdu 4741 Save Labman No.004(2013杭州网络赛)的更多相关文章

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

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

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

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

  3. 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 ...

  4. HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. hdu 4741 Save Labman No.004异面直线间的距离既构成最小距离的两个端点

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

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

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

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

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

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

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

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

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

随机推荐

  1. Android 更好的Activity生命周期回调

    /** * This class allows you to listen to when the user is entering the background (i.e. after a home ...

  2. JS倒计时器一只,顺便复习javascript时间相关函数

    window.onload = function(){ var uS = 604800; //后台提供 : 秒 var day=hour=minute=second=0, timer; var dem ...

  3. js 中 setTimeout()的用法

    setTimeout()在js类中的使用方法   setTimeout (表达式,延时时间)setTimeout(表达式,交互时间)延时时间/交互时间是以豪秒为单位的(1000ms=1s) setTi ...

  4. 剑指offer——已知二叉树的先序和中序排列,重构二叉树

    这是剑指offer中关于二叉树重构的一道题.题目原型为: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2, ...

  5. 使WEBBROWSER 可编辑

    procedure TForm1.CheckBox1Click(Sender: TObject);begin  {这里是让整个页面可编辑, 也可以单独编辑某个元素}  WebBrowser1.OleO ...

  6. Unix/Linux环境C编程入门教程(10) SUSE Linux EnterpriseCCPP开发环境搭建

    安装SUSE企业版以及搭建C/C++开发环境 1.      SUSELinux Enterprise是一款服务器操作系统,异常稳定. 2.设置虚拟机类型. 3.选择稍后安装操作系统. 4.选择SUS ...

  7. AspectJ AOP例子

    最近在学习Spring AOP,其中涉及到AspectJ的AOP框架.主要参考:http://howtodoinjava.com/spring/spring-aop/spring-aop-aspect ...

  8. gdb的user-define command

    搜索: user-defined例子. # save this file in ~/.gdb or some where easy to find. # then in ~/.gdbinit add ...

  9. 【虚拟化实战】容灾设计之四VPLEX

    作者:范军 (Frank Fan) 新浪微博:@frankfan7 VPLEX等存储设备的出现,可以实现双活数据中心,最大程度的有效利用运算和存储资源. 在“容灾设计之三Stretched Clust ...

  10. 修改ubuntu的默认python版本

    ubuntu14.04LTS上装有两个版本的python:python2.7.6与python3.4,默认使用python2.7.6. 可以使用以下命令来修改默认python版本: sudo cp / ...