tetrahedron

传送门

Time Limit: 2000/1000 MS (Java/Others)  
Memory Limit: 65536/65536 K (Java/Others)

Problem Description
Given four points ABCD, if ABCD is a tetrahedron, calculate the inscribed sphere of ABCD.
 
Input
Multiple test cases .
Each test cases contains a line of 12 integers indicating the coordinates of four vertices of ABCD.
Input ends by EOF.

 Output
Print the coordinate of the center of the sphere and the radius, rounded to 4 decimal places.
If there is no such sphere, output "O O O O".

Sample Input
0 0 0 2 0 0 0 0 2 0 2 0
0 0 0 2 0 0 3 0 0 4 0 0

 Sample Output
0.4226 0.4226 0.4226 0.4226
O O O O
 
Author
HIT

Source
2016 Multi-University Training Contest 1
 
 
Solution:
求四面体的内切球的半径和球心坐标。
半径可以通过将体积算两次来求:第一次用向量算,第二次用四个面的面积和乘内切球半径算。
内心的直角坐标可用体积坐标来算。
四面体的体积坐标

$设四面体的四个顶点分别为A_1, A_2, A_3, A_4, 对于空间内任一点P, 我们用\vec{P}表示\vec{OP}$
$对\textbf{四面体内}任意一点P, 有$

\[\vec P =\sum_{i=1}^{4}\lambda_i\vec A_i,\]

\[\sum_{i=1}^{4}\lambda_i=1\]

$四面体体积坐标的几何意义:$

$其各坐标分量是以P为顶点, 以各底面为底的四面体的体积与原四面体的体积之比. 即:$

\[ \lambda_1=\frac{V_{PA_2 A_3A_4}}{V_{A_1A_2A_3A_4}} \]

\[\lambda_2=\frac{V_{PA_1A_3A_4}}{V_{A_1A_2A_3A_4}}\]

\[\lambda_3=\frac{V_{PA_1A_2A_4}}{V_{A_1A_2A_3A_4}}\]

\[\lambda_4=\frac{V_{PA_1A_2A_3}}{V_{A_1A_2A_3A_4}}\]

$记四面体A_1A_2A_3A_4的四个底面的面积分别为S_1, S_2, S_3, S_4, 若P是四面体A_1A_2A_3A_4的内心I, 则有$

\[\lambda_i = \frac{S_i}{S_1+S_2+S_3+S_4}, \quad i=1, 2, 3, 4\]

$故$

\[\vec{OI}=\sum_{i=1}^{4}\lambda_i\vec{A_i}=\frac{\sum\limits_{i=1}^{4}S_i\vec{A_i}}{\sum\limits_{i=1}^{4}S_i}\]

$从而I的直角坐标(x, y, z)为:$

\[x=\frac{\sum_\limits{i=1}^{4}S_ix_i}{\sum_\limits{i=1}^{4}S_i}\]

\[y=\frac{\sum_\limits{i=1}^{4}S_iy_i}{\sum_\limits{i=1}^{4}S_i}\]

\[z=\frac{\sum_\limits{i=1}^{4}S_iz_i}{\sum_\limits{i=1}^{4}S_i}\]

无解的情况对应着四面体四点共面, 即体积为零.

Implementation:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; struct point{
LL x,y,z;
int read(){
return scanf("%lld%lld%lld", &x, &y, &z);
} point operator-(const point &p){
return {x-p.x, y-p.y, z-p.z};
} point operator^(const point &p){ //cross product
return {y*p.z-z*p.y, z*p.x-x*p.z, x*p.y-y*p.x};
}
double operator*(const point &p){ //dot product
return x*p.x+y*p.y+z*p.z;
}
double len(){
return sqrt(x*x+y*y+z*z);
} }p[]; int main(){
for(; ~p[].read(); ){
for(int i=; i<; i++) p[i].read(); LL vol=abs(((p[]-p[])^(p[]-p[]))*(p[]-p[])); if(!vol){
puts("O O O O"); //error-prone: O, not 0
continue;
} double s[], sum=;
point vec[]; for(int i=; i<; i++){
for(int j=; j<; j++)
if(j!=i){
for(int k=, l=; k<; k++)
if(k!=j && k!=i)
vec[l++]=p[k]-p[j];
break;
}
s[i]=abs((vec[]^vec[]).len()), sum+=s[i];
} double tot=, x, y, z;
for(int i=; i<; i++) tot+=s[i]*p[i].x;
x=tot/sum;
tot=;
for(int i=; i<; i++) tot+=s[i]*p[i].y;
y=tot/sum;
tot=;
for(int i=; i<; i++) tot+=s[i]*p[i].z;
z=tot/sum;
printf("%.4f %.4f %.4f %.4f\n", x, y, z, vol/sum);
}
}

HDU #5733 tetrahedron的更多相关文章

  1. HDU 5733 tetrahedron(计算几何)

    题目链接 tetrahedron 题目大意 输入一个四面体求其内心,若不存在内心则输出"O O O O" 解题思路 其实这道题思路很简单,只要类推一下三角形内心公式就可以了. 至于 ...

  2. hdu 5733 tetrahedron 四面体内切球球心公式

    tetrahedron Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. 【HDU 5733】tetrahedron

    输入4个点三维坐标,如果是六面体,则输出内切球的球心坐标和半径. 点pi对面的面积为si,点a,b,c组成的面积=|ab叉乘ac|/2. 内心为a,公式: s0=s1+s2+s3+s4 a.x=∑si ...

  4. hdu 5726 tetrahedron 立体几何

    tetrahedron/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Given four p ...

  5. hdu 6814 Tetrahedron 规律+排列组合逆元

    题意: 给你一个n,你需要从1到n(闭区间)中选出来三个数a,b,c(可以a=b=c),用它们构成一个直角四面体的三条棱(可看图),问你从D点到下面的三角形做一条垂线h,问你1/h2的期望 题解: 那 ...

  6. HDU 5839 Special Tetrahedron (计算几何)

    Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...

  7. HDU 5839 Special Tetrahedron

    HDU 5839 Special Tetrahedron 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n ...

  8. HDU 5839 Special Tetrahedron 计算几何

    Special Tetrahedron 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...

  9. HDU 5839 Special Tetrahedron (2016CCPC网络赛08) (暴力+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不 ...

随机推荐

  1. MYSQL查询优化

    目前手头有个查询: SELECT LPP.learning_project_pupilID, SL.serviceID, MAX(LPPO.start_date), SUM(LPPOT.license ...

  2. MvvmLight ToolKit .Net4.5版本 CanExecute不能刷新界面bug

    一 问题重现    1.在使用最新版本v5.1的MvvmLight中(其实这个问题很早就有了),发现CanExecute不能很好地工作了.一个简单的工程,只有MainWindow和MainWindow ...

  3. 解决Kafka-1194问题

    生产环境中使用Kafka作为日志处理的中间件,系统结构是这样的.自12月上线一个多月来,系统运行稳定. 用过kafka的都知道,Kafka产生的消息全部存储到硬盘文件中,并且在消息被消费后不会被立即删 ...

  4. 【跟着子迟品underscore】从用 `void 0` 代替 `undefined` 说起

    Why underscore 最近开始看 underscore源码,并将 underscore源码解读 放在了我的 2016计划 中. 阅读一些著名框架类库的源码,就好像和一个个大师对话,你会学到很多 ...

  5. 创业这三年¥.NET之尴尬处境

    创业这三年#迈出第一步 创业这三年@各种奇遇 之前写的文章有兴趣的大家可以看看. 本来没有打算写这样一篇会遭人拍砖的文章,但是发现大家每天忙于编码,对市场环境..Net生态没有一个真实.多角度的认识, ...

  6. 各地IT薪资待遇讨论

    作为一个搞.net开发的程序员,在北京混了三年半,最近准备辞职到上海找工作.由于对上海的IT行业还不是很了解,在这里想让上海的同行们说下你们的情况,以方便我对自己在上海的定位,当然,其余城市的的同行们 ...

  7. .net框架中少有人知的扩展cmod

    最近在利用metadata api抽取.net的原数据信息,发现了不少“坑”,也发现了不少常年用着c#的人都不知道的扩展. 说到.net原数据的可扩展性,第一个让人能想到的就是CustomAttrib ...

  8. Web软件安全攻击

  9. ASP.NET利用WINRar实现在线解压缩文件

    一.肯定是服务器必须装了winrar这个软件了. 二.创建Helper类,如下: using System; using System.Collections.Generic; using Syste ...

  10. canvas模拟重力效果

    总结 速度和加速度是动画的基础元素,其中两者都是向量,包括了一个重要因素:方向. 要学会应用 分解 和 合成 ,将速度或加速度分解到x.y轴上,然后将每条轴上的加速度或速度相加,然后再分别与物体的位置 ...