获得 新的模板了///  此模板 有线段和线段的最短距离方法,同时包含线段与线段的最短距离;
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#define eps 1e-10
#define inf 0x1f1f1f1f
using namespace std; int dcmp( double a ){ if( abs(a) < eps ) return 0; if(a > 0) return 1;return -1;}
struct point{
double x,y,z;
point(){}
point( double x,double y,double z ):x(x),y(y),z(z){}
};
typedef point Vector ;
point operator + ( point a,point b ){
return point( a.x+b.x , a.y+b.y , a.z+b.z );
}
// 确定一个平面;一般式;
struct plane{
double a,b,c,d;
plane( double a = 0,double b = 0,double c = 0,double d = 0 ):a(a),b(b),c(c),d(d){}
};
point operator - ( point a,point b ){
return point( a.x-b.x , a.y-b.y, a.z-b.z );
}
point operator * ( point a,double p ){
return point( a.x*p , a.y*p , a.z*p );
}
point operator / ( point a,double p ){
return point( a.x/p , a.y/p , a.z/p );
}
bool operator == ( point a,point b ){
if( dcmp(a.x-b.x) == 0&& dcmp(a.y-b.y) == 0 && dcmp(a.z-b.z) == 0 )return 1;
return 0;
}
double Dot( point a,point b ){ return a.x*b.x + a.y*b.y + a.z*b.z; }
double Length( point a ){ return sqrt(Dot(a,a));}
double Angle( point a,point b ){ return acos(Dot(a,b))/Length(a)/Length(b); }
// 点到 平面p0 - n 的距离;n 必须为单位向量 n 是平面法向量
double p_po_n( const point &p,const point &po,const point n ){
return abs(Dot( p-po,n ));
}
// 点在 平面p0 - n 的投影 ; n 必须为单位向量 n 是平面法向量
point p_po_n_jec( const point &p,const point &p0,const point &n ){
return p-n*Dot( p-p0,n );
}
// 直线p1 p2 在平面 p0 - n 的交点,假设交点存在;唯一
point p_p_p( point p1,point p2,point p0,point n ){
point v = p2 - p1;
double t = ( Dot(n,p0-p1)/Dot(n,p2-p1) );
return p1 + v*t;
}
point cross( point a,point b ){
return point( 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 area( point a,point b,point c ){ return Length(cross(b-a,c-a)); }
double dis_to_line( point p, point a,point b ){
point v1 = b-a, v2 = p-a;
return Length( cross(v1,v2)/Length(v1) );
}
// p 到 ab 线段的距离
double dis_to_segm( point p,point a,point b ){
if( a == b )return Length(p-a);
point v1 = b-a, v2 = p-a, v3 = p-b;
if( dcmp( Dot(v1,v2) ) < 0 ) return Length(v2);
else if( dcmp( Dot(v1,v3) ) > 0 ) return Length(v3);
else return Length(cross(v1,v2))/Length(v1);
}
// 四面体的体积
double dis_l_to_l( point a,point b,point lt,point rt )
{
while( abs(rt.x - lt.x) > eps || abs(rt.y - lt.y) > eps || abs( rt.z - lt.z) > eps )
{
point temp; temp = lt + ( rt - lt )/3.0;
point now; now = lt + ( rt - lt )/3.0*2.0;
if( dis_to_segm(temp,a,b) < dis_to_segm(now,a,b) )
rt = now;
else lt = temp;
}
return dis_to_segm( rt,a,b );
}
// 获取平面 a*x + b*y + c*z + d; 由;两个向量 和 一个平面一个点确定一个平面
plane get_plane( Vector a,Vector b,point c )
{
Vector p = cross( a,b ); // 由平面两个向量 可以确定平面法向量;
double d = ( p.x*c.x + p.y*c.y + p.z*c.z)*-1;
return plane( p.x,p.y,p.z,d );
}
// 获取 直线与平面的交点;
point get_point( plane p,point c,point d )
{
Vector v = c - d;
double t = p.a*c.x+p.b*c.y + p.c*c.z + p.d ;
double s = p.a*(d.x - c.x) + p.b*(d.y-c.y) + p.c*(d.z - c.z);
double k = t/s;
return c + v*k;
} point A[5];
int main( )
{
int T; scanf("%d",&T);
while( T-- )
{
for( int i = 1; i <= 4; i++ )
scanf("%lf %lf %lf",&A[i].x,&A[i].y,&A[i].z);
Vector v1 = A[2] - A[1];
Vector v2 = A[4] - A[3];
Vector v3 = cross( v1,v2 ); // 获取公垂线;
plane a1 = get_plane( v1,v3,A[1] ); // 两个向量 和一个点 确定一个平面;
plane a2 = get_plane( v2,v3,A[3] );
point p1 = get_point( a1,A[4],A[3] ); // 获取交点;
point p2 = get_point( a2,A[1],A[2] );
printf("%.6lf\n",Length(p1-p2));
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",p2.x,p2.y,p2.z,p1.x,p1.y,p1.z);
}
return 0;
}

  

HDU 4741的更多相关文章

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

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

  2. hdu 4741 2013杭州赛区网络赛 dfs ***

    起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...

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

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

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

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

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

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

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

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

  7. 2013杭州网络赛D题HDU 4741(计算几何 解三元一次方程组)

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

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

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

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

随机推荐

  1. ios开发--animation flash动画

        /**  *  showAnimationFlash  */ + (void)showAnimationFlashWithView:(UIView *)animationView durati ...

  2. PHP组合模式

    一.组合模式简述 1.组合定义了一个单根继承体系,使具有不同职责的集合可以并肩工作 2.如果想像对待单个对象一样对待组合对象,那么组合模式十分有用 3.组合模式不能很好地在关系数据库中保存数据,但却非 ...

  3. MAC的一些实用

    重置Dock, Launchpad defaults write com.apple.dock ResetLaunchPad -bool true; killall Dock;

  4. WPF之RichTextBox丢失光标仍然选中文本

    描述:开发中完成了一个类似于Word的悬浮工具栏功能,选中文本之后可以自动弹出一个工具栏.可以修改字体.字体大小等功能,问题来了,我发现当去进行操作的时候原本选中的RichTextBox的内容的颜色会 ...

  5. 280. Wiggle Sort

    题目: Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] ...

  6. iOS:地图:MapKit和CoreLocation

    地图:MapKit和CoreLocation 简介: 现在很多的社交软件都引入了地图和定位功能,要想实现这2大功能,那就不得不学习其中的2个框架:MaKit和CoreLocation CoreLoca ...

  7. Myeclipse 10 破解说明

    一,准备阶段 : 1. 破解软件(网上有下载) 2. JDK软件(免费软件) 二,开始破解: 1. 关闭MyEclipse 10.0 2. 安装 JDK 三,特殊说明: 有些机器安装时会出现run.b ...

  8. java cache过期策略两种实现,一个基于list轮询一个基于timer定时

    最近项目要引入缓存机制,但是不想引入分布式的缓存框架,所以自己就写了一个轻量级的缓存实现,有两个版本,一个是通过timer实现其超时过期处理,另外一个是通过list轮询.       首先要了解下ja ...

  9. SQL Server ->> 关于究竟ALTER INDEX ... REBUILD会不会导致改变索引选项和Filegroup的验证

    其实之前做过类型的验证,不过影响不是特别深,只是记得不会改变DATA COMPRESSION,那今天再次遇到这个问题就再拿出来验证一下.随便写个脚本验证下.ALTER INDEX ... REBUIL ...

  10. 正则表达式 Regular Expressions

    python method search wordlist = [w for w in nltk.corpus.words.words('en' ) ifw.islower()] print [w f ...