tetrahedron/center>

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5726

Description

Given four points ABCD, if ABCD is a tetrahedron, calculate the inscribed sphere of ABCD.

Input

Multiple test cases (test cases ≤100).

Each test cases contains a line of 12 integers [−1e6,1e6] indicate 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

Hint

题意

给你一个四面体,求内切球的坐标和半径。

题解:

网上去搜了一堆公式,随便抄了抄就过去了。

直接百度就好了,什么体积坐标什么的。。。

wa了半天,队友才发现是他自己叉积写错了,尴尬。

代码

#include <bits/stdc++.h>

using namespace std;

struct point
{
double x,y,z;
}P[5];
struct pingmian
{
double a,b,c,d;
}pm[5];
double area[5]; double P2planeDist(double x, double y, double z, double a, double b, double c, double d)
{
return fabs(a*x+b*y+c*z+d)/sqrt(a*a+b*b+c*c);
}
double dist(point p0,point p1)
{
return sqrt((p0.x-p1.x)*(p0.x-p1.x)+(p0.y-p1.y)*(p0.y-p1.y)+(p0.z-p1.z)*(p0.z-p1.z));
}
int check(point p0,point p1,point p2)
{
p1.x-=p0.x,p1.y-=p0.y,p1.z-=p0.z;
p2.x-=p0.x,p2.y-=p0.y,p2.z-=p0.z;
if((p1.x*p2.y==p1.y*p2.x)&&(p1.x*p2.z==p1.z*p2.x)&&(p1.y*p2.z==p1.z*p2.y)) return 0;
return 1;
}
point mul(point p0,point p1)
{
point p2;
p2.x=p0.y*p1.z-p0.z*p1.y;
p2.y=-p0.x*p1.z+p0.z*p1.x;
p2.z=p0.x*p1.y-p0.y*p1.x;
return p2;
}
void cal(int p,point p0,point p1,point p2)
{
double a=dist(p0,p1),b=dist(p1,p2),c=dist(p0,p2);
double d=(a+b+c)/2.0;
area[p]=sqrt(d*(d-a)*(d-b)*(d-c));
p1.x-=p0.x,p1.y-=p0.y,p1.z-=p0.z;
p2.x-=p0.x,p2.y-=p0.y,p2.z-=p0.z;
point p3=mul(p1,p2);
pm[p].a=p3.x,pm[p].b=p3.y,pm[p].c=p3.z;
pm[p].d=-(pm[p].a*p0.x+pm[p].b*p0.y+pm[p].c*p0.z);
return ;
} int main()
{
while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&P[0].x,&P[0].y,&P[0].z,&P[1].x,&P[1].y,&P[1].z,&P[2].x,&P[2].y,&P[2].z,&P[3].x,&P[3].y,&P[3].z)!=EOF)
{
if(!(check(P[0],P[1],P[2])&&check(P[0],P[1],P[3])&&check(P[0],P[2],P[3])&&check(P[1],P[2],P[3])))
{
printf("O O O O\n");
continue;
}
cal(3,P[0],P[1],P[2]);
cal(2,P[0],P[1],P[3]);
cal(1,P[0],P[2],P[3]);
cal(0,P[1],P[2],P[3]);
double r=area[3]*P2planeDist(P[3].x,P[3].y,P[3].z,pm[3].a,pm[3].b,pm[3].c,pm[3].d)/(area[0]+area[1]+area[2]+area[3]);
// cout<<pm[3].a<<" "<<pm[3].b<<" "<<pm[3].c<<" "<<pm[3].d<<endl;
// cout<<P2planeDist(P[3].x,P[3].y,P[3].z,pm[3].a,pm[3].b,pm[3].c,pm[3].d)<<endl;
point ans;
if(r<1e-9)
{
printf("O O O O\n");
continue;
}
// cout<<area[0]<<" "<<area[1]<<" "<<area[2]<<" "<<area[3]<<endl;
ans.x=(area[0]*P[0].x+area[1]*P[1].x+area[2]*P[2].x+area[3]*P[3].x)/(area[0]+area[1]+area[2]+area[3]);
ans.y=(area[0]*P[0].y+area[1]*P[1].y+area[2]*P[2].y+area[3]*P[3].y)/(area[0]+area[1]+area[2]+area[3]);
ans.z=(area[0]*P[0].z+area[1]*P[1].z+area[2]*P[2].z+area[3]*P[3].z)/(area[0]+area[1]+area[2]+area[3]);
printf("%.4f %.4f %.4f %.4f\n",ans.x,ans.y,ans.z,r);
}
return 0;
}

hdu 5726 tetrahedron 立体几何的更多相关文章

  1. HDU 5726 GCD 区间GCD=k的个数

    GCD Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  2. HDU 5726 GCD (RMQ + 二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...

  3. HDU 5726 GCD(DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5726 [题目大意] 给出数列An,对于询问的区间[L,R],求出区间内数的GCD值,并且求出GCD ...

  4. HDU 5726 GCD(RMQ+二分)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5726 题意:给出一串数字,现在有多次询问,每次询问输出(l,r)范围内所有数的gcd值,并且输出有多 ...

  5. hdu 5726 GCD 暴力倍增rmq

    GCD/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence ...

  6. HDU #5733 tetrahedron

    tetrahedron 传送门 Time Limit: 2000/1000 MS (Java/Others)   Memory Limit: 65536/65536 K (Java/Others) P ...

  7. HDU 5733 tetrahedron(计算几何)

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

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

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

  9. HDU 5726 GCD

    传送门 GCD Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem ...

随机推荐

  1. [整理]zepto的初次使用

    http://www.css88.com/doc/zeptojs_api/ http://chaoskeh.com/blog/some-experience-of-using-zepto.html

  2. CSS-3 Transition 的使用

    css的transition允许css的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击.获得焦点.被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值." tran ...

  3. Linux - sed 文本操作

    SED 是一项Linux指令,功能同awk类似,差别在于,sed简单,对列处理的功能要差一些,awk的功能复杂,对列处理的功能比较强大. sed全称是:Stream EDitor 调用sed命令有两种 ...

  4. scala笔记之惰性赋值(lazy)

    一.lazy关键字简介 lazy是scala中用来实现惰性赋值的关键字,被lazy修饰的变量初始化的时机是在第一次使用此变量的时候才会赋值,并且仅在第一次调用时计算值,即值只会被计算一次,赋值一次,再 ...

  5. ASP.NET程序发布

    详细流程请参考文章:https://www.cnblogs.com/wangjiming/p/6286045.html 主要补充个人操作过程中遇到的问题: 1)网站发布完成后,站点下没有aspnet_ ...

  6. nested exception is com.svorx.core.dao.PersistenceException

    在quartz定时执行任务的时候,hibernate报错,在只读事务中进行了update语句: [ERROR] 2018/08/03 10:35:00,827 org.quartz.core.JobR ...

  7. BGM时长

    1.can u feel it 00:08-00:30 22s 2.纤夫的爱 00:43-00:54 11s 3.渡情 00:55-01:52 57s 4.nobody 01:56-02:25 29s ...

  8. ajax请求成功但不执行success-function回调函数的问题

    在success:function(data){}下面加个error:function(){},看看是不是出错了走了error.如果是,说明返回值类型不符合要求. 比如:下面代码返回String类型. ...

  9. mysql及linux发行版下载源

    MySQL国内镜像资源 搜狐开源镜像站:http://mirrors.sohu.com/ 国内开源镜像站点汇总 http://segmentfault.com/a/1190000000375848   ...

  10. centos6.5环境Redis下载及编译安装

    centos6.5环境Redis下载及编译安装 1:官方站点: http://redis.io/download 下载最新版或者最新stable版 2:解压源码并进入目录 tar -zxvf redi ...