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. bzoj千题计划188:bzoj1923: [Sdoi2010]外星千足虫 (高斯—若尔当消元法解异或方程组)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1923 #include<cstdio> #include<cstring> ...

  2. shell test条件判断

    test 条件判断 # 符号 [ ] 等同  test命令 test -lt # 判断大小 echo $? # 查看上句test命令返回状态 # 结果0为真,1为假 test -n "hel ...

  3. 【ARTS】01_02_左耳听风-20181119~1125

    Algorithm 做一个 leetcode 的算法题 Unique Email Addresses https://leetcode.com/problems/unique-email-addres ...

  4. MySQL乱码问题以及utf8mb4字符集

    MySQL乱码问题以及utf8mb4字符集 1.乱码 推荐大家看 深入MySQL字符集设置 ,区分检查client端.server端的编码:最简单暴力的方式,是在所有的环节都显式明确的指定相同的编码, ...

  5. Uploadify3.2中文提示

    版本:Uploadify Version 3.2官网:http://www.uploadify.com Uploadify是一款基于Jquery的上传插件,用起来很方便.但上传过程中的提示语言为英文, ...

  6. springmvc上下文与springcontext上下文的关系

    内容摘自:springmvc与spring上下文的关系 原理区别 一直不清楚springmvc-servlet.xml配置与spring.xml两个配置文件出现的上下文关系.今天找到一上面的文章,倒是 ...

  7. GET和POST两种基本请求方法的区别(转载)

    get与post请求的区别: 通常回答: GET在浏览器回退时是无害的,而POST会再次提交请求. GET产生的URL地址可以被Bookmark,而POST不可以. GET请求会被浏览器主动cache ...

  8. python3 之__str__

    当某个类定义了__str__方法是,打印该类的实例对象就是打印__str__方法return出来的数据 示例: class Cat: """定义了一个Cat类" ...

  9. java 添加自己的工具包

    一. 在添加工具包前环境变量要定位到当前目录, export CLASSPATH=.:/home/share/ 添加工具类 我的目录\\192.168.1.101\share\share\net\fe ...

  10. Oracle学习笔记:外连接(+)的用法

    Oracle中常用 left join 和 right join 来进行外连接,同时,oracle也支持 (+) 的特殊用法,也是表示外连接,并且总是放在非主表的一方. 例如: 左外连接: selec ...