HDU 4617 Weapon 三维计算几何
题意:给你一些无限长的圆柱,知道圆柱轴心直线(根据他给的三个点确定的平面求法向量即可)与半径,判断是否有圆柱相交。如果没有,输出柱面最小距离。
一共只有30个圆柱,直接暴力一下就行。
判相交/相切:空间直线距离是否小于等于两圆柱半径和
若无相交,求最小:空间直线距离-两圆柱半径和
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; const double EPS = 1e-;
const int MAXN = ; struct Point3 //空间点
{
double x, y, z;
}; struct Line3 //空间直线
{
Point3 a, b;
}; struct plane3 //空间平面
{
Point3 a, b, c;
plane3(){}
plane3( Point3 a, Point3 b, Point3 c ):
a(a), b(b), c(c) { }
}; struct Cylinder
{
Point3 center; //圆柱轴线经过的一点
Point3 a, b; //与中心点在同一平面的两点
Line3 FaXian; //轴线
double R; //圆柱半径
}; Cylinder CC[MAXN]; Point3 Read_Point()
{
Point3 p;
scanf("%lf%lf%lf", &p.x, &p.y, &p.z );
return p;
} double dcmp( double a )
{
if ( fabs( a ) < EPS ) return ;
return a < ? - : ;
} //三维叉积
Point3 Cross3( Point3 u, Point3 v )
{
Point3 ret;
ret.x = u.y * v.z - v.y * u.z;
ret.y = u.z * v.x - u.x * v.z;
ret.z = u.x * v.y - u.y * v.x;
return ret;
} //三维点积
double Dot3( Point3 u, Point3 v )
{
return u.x * v.x + u.y * v.y + u.z * v.z;
} //矢量差
Point3 Subt( Point3 u, Point3 v )
{
Point3 ret;
ret.x = u.x - v.x;
ret.y = u.y - v.y;
ret.z = u.z - v.z;
return ret;
} //取平面法向量
Point3 NormalVector( plane3 s )
{
return Cross3( Subt( s.a, s.b ), Subt( s.b, s.c ) );
}
Point3 NormalVector( Point3 a, Point3 b, Point3 c )
{
return Cross3( Subt( a, b ), Subt( b, c ) );
} //两点距离
double TwoPointDistance( Point3 p1, Point3 p2 )
{
return sqrt( (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y) + (p1.z - p2.z)*(p1.z - p2.z) );
} //向量的模
double VectorLenth( Point3 p )
{
return sqrt( p.x*p.x + p.y*p.y + p.z*p.z );
} //空间直线距离
double LineToLine( Line3 u, Line3 v )
{
Point3 tmp = Cross3( Subt( u.a, u.b ), Subt( v.a, v.b ) );
return fabs( Dot3( Subt(u.a, v.a), tmp ) ) / VectorLenth(tmp);
} int N; int main()
{
int T;
scanf( "%d", &T );
while ( T-- )
{
scanf( "%d", &N );
for ( int i = ; i < N; ++i )
{
CC[i].center = Read_Point();
CC[i].a = Read_Point();
CC[i].b = Read_Point();
CC[i].R = VectorLenth( Subt( CC[i].a, CC[i].center ) );
CC[i].FaXian.a = CC[i].center;
CC[i].FaXian.b = Subt( CC[i].center, NormalVector( CC[i].center, CC[i].a, CC[i].b ) );
} bool ok = true;
double MinAns = 1e200;
for ( int i = ; ok && i < N; ++i )
for ( int j = i + ; ok && j < N; ++j )
{
double tmp = LineToLine( CC[i].FaXian, CC[j].FaXian );
if ( dcmp( tmp - ( CC[i].R + CC[j].R ) ) <= )
{
ok = false;
break;
}
MinAns = min( MinAns, tmp - ( CC[i].R + CC[j].R ) );
} if ( ok ) printf( "%.2f\n", MinAns );
else puts("Lucky");
}
return ;
}
HDU 4617 Weapon 三维计算几何的更多相关文章
- hdu 4617 Weapon【异面直线距离——基础三维几何】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others) ...
- HDU 4617 Weapon (简单三维计算几何,异面直线距离)
Weapon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- HDU 4617 Weapon(三维几何)
Problem Description Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a c ...
- hdu 4617 Weapon
http://acm.hdu.edu.cn/showproblem.php?pid=4617 三维几何简单题 多谢高尚博学长留下的模板 代码: #include <iostream> #i ...
- hdu 4617 Weapon(叉积)
大一学弟表示刚学过高数,轻松无压力. 我等学长情何以堪= = 求空间无限延伸的两个圆柱体是否相交,其实就是叉积搞一搞 详细点就是求两圆心的向量在两直线(圆心所在的直线)叉积上的投影 代码略挫,看他的吧 ...
- HDU 5130 Signal Interference(计算几何 + 模板)
HDU 5130 Signal Interference(计算几何 + 模板) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5130 Descripti ...
- hdu 1174:爆头(计算几何,三维叉积求点到线的距离)
爆头 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )
空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...
随机推荐
- 互联网产品设计常用文档类型-BRD、MRD、PRD、FSD (
BRD Business Requirements Document,商业需求文档.这是产品声明周期中最早的问的文档,再早就应该是脑中的构思了,其内容涉及市场分析,销售策略,盈利预测等,通常是和老大们 ...
- 我教女朋友学编程html系列(5) html中table的用法和例子
女朋友不是学计算机的,但是现在从事计算机行业,做技术支持,她想学习编程,因此我打算每天教她一点点,日积月累,带她学习编程,如果其他初学者感兴趣,可以跟着学. 为了将table介绍的简单.生动,具有实战 ...
- Careercup - Microsoft面试题 - 6314866323226624
2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...
- 【转】oracle number与java中long、int的对应
Oracle数据库中number类型在hibernate的引用 1)如果不指定number的长度,或指定长度n>18 id number not null,转换为pojo类时,为java.mat ...
- selenium--嵌套frame定位
网页源码: 案例1 :iframe有id.name属性 网页上有3个frame:header.menu.main,分别代码顶部.左侧.右侧(其中menu.main在另外一个frameset中) 如何定 ...
- 图片上传前的预览(PHP)
1.先创建一个file表单域,我们需要用它来浏览本地文件.<form name="form1" id="form1" method="post& ...
- 中断(interrupt)、异常(exception)、陷入(trap)
原文出处:http://lhk518.blog.163.com/blog/static/3153998320084263554749/ 中断:是为了设备与CPU之间的通信.典型的有如服务请求,任务完成 ...
- 版本控制 - SVN/TortoiseSVN
研读了blog: 1. http://www.open-open.com/lib/view/open1346982569725.html 2. http://www.360doc.com/conte ...
- GPU crash unmap page access
这类gpu crash是 texture 没有gpu address 调试方法 去看texture, texture state 里面allocateMemoryBlock...这里面有gpuadd ...
- Kali-linux安装之后的简单设置
1.更新软件源:修改sources.list文件:leafpad /etc/apt/sources.list然后选择添加以下适合自己较快的源(可自由选择,不一定要全部): #官方源deb http:/ ...