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;
}

最新文章

  1. Java动态加载JAR包
  2. 由overflow-x:scroll产生的收获
  3. NOT IN查询效率低,用它的等效写法提高效率。
  4. def文件格式
  5. QT 环境下开发socketCan接口程序
  6. A. Sorting Railway Cars
  7. TCP Connection Establishment and Termination
  8. table 表格隔行换色实现
  9. HDU 5037 FROG (贪婪)
  10. PAT1084:Broken Keyboard
  11. XPath定位时,使用文本的方法小技巧。
  12. js中this指向、箭头函数
  13. 为何串口dma发送数据可能不完整
  14. html5 图片上传 预览
  15. CentIOS PHP 扩展库
  16. 三公网络监督平台APP上线,源代码出售。
  17. Netty in action—Netty中的ByteBuf
  18. 分词工具比较及使用(ansj、hanlp、jieba)
  19. C# 使用IP端口网络打印图片
  20. SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树

热门文章

  1. JS倒计时器一只,顺便复习javascript时间相关函数
  2. cad实时平移快捷键
  3. POJ 2686 Traveling by Stagecoach 壮压DP
  4. Android中ViewStub组件使用
  5. OpenGL中glRotatef()函数究竟对矩阵做了什么
  6. swift3.0 扩展、协议(4)
  7. PHP 操作redis 详细讲解转的
  8. 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)
  9. SendMessage用法实例
  10. My97DaePicker 用js实现文本框日期相减求天数