tetrahedron
题意:
求解一个四面体的内切球。
解法:
首先假设内切球球心为$(x0,x1,x2)$,可以用$r = \frac{3V}{S_1+S_2+S_3+S_4}$得出半径,
这样对于四个平面列出三个方程,解得
$x_n = \sum_{i=0}^3{Ai_{x_n} \cdot S_i } / (S_1 + S_2 + S_3 + S_4)$
这样,即可得出内切球。
时间复杂度$O(1)$。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> #define LD double
#define sqr(x) ((x)*(x))
#define eps 1e-13 using namespace std; struct node
{
LD x,y,z;
void scan()
{
scanf("%lf%lf%lf",&x,&y,&z);
}
void print()
{
printf("%.4lf %.4lf %.4lf\n",x,y,z);
}
LD length()
{
return sqrt(sqr(x)+sqr(y)+sqr(z));
}
node operator+(const node &tmp)
{
return (node){x+tmp.x,y+tmp.y,z+tmp.z};
}
node operator-(const node &tmp)
{
return (node){x-tmp.x,y-tmp.y,z-tmp.z};
}
node operator/(LD tmp)
{
return (node){x/tmp,y/tmp,z/tmp};
}
node operator*(LD tmp)
{
return (node){x*tmp,y*tmp,z*tmp};
}
}; node cross(node a,node b)
{
node ans;
ans.x = a.y*b.z - b.y*a.z;
ans.y = b.x*a.z - a.x*b.z;
ans.z = a.x*b.y - b.x*a.y;
return ans;
} LD dist(node a,node b)
{
return (b-a).length();
} LD dot(node a,node b)
{
return a.x*b.x + a.y*b.y + a.z*b.z;
} LD get_angle(node a,node b)
{
LD tmp = dot(a,b)/a.length()/b.length();
return acos(tmp);
} node get_node(node A,node B,node C)
{
LD Lth = (B-A).length() + (C-A).length() + (C-B).length();
cout << sqr(Lth-) << endl;
LD r = fabs(cross(B-A,C-A).length()) / Lth;
cout << r*r << endl;
node v1 = C-A;
node v2 = B-A;
node v = (v1+v2)/(v1+v2).length();
LD d = (C-A).length()/;
LD L = sqrt(sqr(d)+sqr(r));
v = v*L;
return A+v;
} int main()
{
node A,B,C,D;
while(~scanf("%lf%lf%lf",&A.x,&A.y,&A.z))
{
B.scan();
C.scan();
D.scan();
if(fabs(dot(cross(B-A,C-A),D-A)) < eps)
{
puts("O O O O");
continue;
}
LD S1 = fabs(cross(B-D,C-D).length())/;
LD S2 = fabs(cross(D-A,C-A).length())/;
LD S3 = fabs(cross(B-A,D-A).length())/;
LD S4 = fabs(cross(B-A,C-A).length())/;
LD Ve = fabs(dot(cross(B-A,C-A),D-A))/;
LD R = *Ve / ((S1+S2+S3+S4));
node ans;
ans.x = (S1*A.x + S2*B.x + S3*C.x + S4*D.x)/(S1+S2+S3+S4);
ans.y = (S1*A.y + S2*B.y + S3*C.y + S4*D.y)/(S1+S2+S3+S4);
ans.z = (S1*A.z + S2*B.z + S3*C.z + S4*D.z)/(S1+S2+S3+S4);
printf("%.4lf %.4lf %.4lf %.4lf\n",ans.x,ans.y,ans.z,R);
}
return ;
}
/*
0 0 0 2 0 0 0 0 2 0 2 0
0 0 0 2 0 0 3 0 0 4 0 0
*/
tetrahedron的更多相关文章
- HDU #5733 tetrahedron
tetrahedron 传送门 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) P ...
- CodeForces 166E -Tetrahedron解题报告
这是本人写的第一次博客,学了半年的基础C语言,初学算法,若有错误还请指正. 题目链接:http://codeforces.com/contest/166/problem/E E. Tetrahedro ...
- E. Tetrahedron(数学推导)
E. Tetrahedron 分类: AC路漫漫2013-08-08 16:07 465人阅读 评论(0) 收藏 举报 time limit per test 2 seconds memory lim ...
- 计算几何----判断空间点是否在一个四面体(tetrahedron)内部
DESCRIPTION: 判断空间点 P(x, y, z)是否在一个四面体的内部? Let the tetrahedron have vertices V1 = (x1, y1, z1) V2 = ( ...
- (四面体)CCPC网络赛 HDU5839 Special Tetrahedron
CCPC网络赛 HDU5839 Special Tetrahedron 题意:n个点,选四个出来组成四面体,要符合四面体至少四条边相等,若四条边相等则剩下两条边不相邻,求个数 思路:枚举四面体上一条线 ...
- HDU 5839 Special Tetrahedron (计算几何)
Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
- HDU 5839 Special Tetrahedron
HDU 5839 Special Tetrahedron 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n ...
- HDU 5839 Special Tetrahedron 计算几何
Special Tetrahedron 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
- hdu 5726 tetrahedron 立体几何
tetrahedron/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Given four p ...
- CF 166E Tetrahedron
E. Tetrahedron time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- 在CentOS 7上构建RAID5、LVM和SAMBAserver(5)——架设SAMBAserver
在CentOS 7上构建RAID5.LVM和SAMBAserver(5)--架设SAMBAserver 6. 架设SAMBAserver 6.1. 预备 本节的任务是配置SAMBA服务,共享/home ...
- Web框架Django(二)
一.Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层 ...
- 网络通讯框架MINA和XSCOCKET的简单比较
http://www.blogjava.net/ghostdog/archive/2008/06/10/MinaVsXsocket.html实在无聊,考虑把当前应用的通讯模式由http移植为socke ...
- 关于Win8 用不了USB转串口驱动
win8系统必需要关闭设备驱动自己主动更新,否则联网更新的驱动是用不了的.操作过程例如以下: 打开控制面板,搜索"设备".更改设备安装设置 watermark/2/text/aHR ...
- 显卡接口PCI、VGA、PCIE
转:1.PCIe扫盲系列博文连载 2.http://blog.sina.com.cn/s/blog_a73f94190102w2j2.html 1.AGP(Accelerated Graphics P ...
- mysql查询sql中检索条件为大批量数据时处理
当userIdArr数组值为大批量时,应如此优化代码实现
- Jenkins + Maven + TestNG参数化调用测试用例
希望实现的场景:Jenkins中的Job可针对不同浏览器,不同环境,运行不同的测试用例集,但测试用例只保持一份. 具体实现的思路:在运行Jenkins Job时传入参数,运行 mvn test 命 ...
- 使用UIWebView载入本地或远程server上的网页
大家都知道,使用UIWebView载入本地或远程server上的网页,sdk提供了三个载入接口: - (void)loadRequest:(NSURLRequest *)request; - (voi ...
- Android-通过SlidingMenu高仿微信6.2最新版手势滑动返回(二)
转载请标明出处: http://blog.csdn.net/hanhailong726188/article/details/46453627 本文出自:[海龙的博客] 一.概述 在上一篇博文中,博文 ...
- EasyDarwin开源流媒体云平台之语音对讲功能设计与实现
本文由EasyDarwin开源团队成员Alex贡献:http://blog.csdn.net/cai6811376/article/details/52006958 EasyDarwin云平台一直在稳 ...