hdu 5733 tetrahedron 求四面体内切球球心坐标及半径大小
来源:互联网 发布:图片分割打印软件 编辑:程序博客网 时间:2024/04/30 01:18
tetrahedron
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 720 Accepted Submission(s): 291
Problem 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.
Each test cases contains a line of 12 integers
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".
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.4226O O O O
Author
HIT
Source
2016 Multi-University Training Contest 1
Recommend
wange2014 | We have carefully selected several similar problems for you: 5751 5750 5749 5748 5747
题意:给出四个点,要你求四面体内切球球心坐标及半径大小。无解输出"O O O O"。
解:首先如果四点共面,必然无解。(我的判断方法是:ABC三点组成的平面法向量n和向量AD如果点乘为0,那么四点共面)
否则,必然有解(四面体必有内切球,可以用分角面证明)
内切球球心(x,y,z)的求法是
令 S= S△ABC+S△ACD+S△ABD+S△BCD;
x= (S△ABC*D.x+S△ACD*B.x+S△ABD*C.x+S△BCD*A.x)/S;
y= (S△ABC*D.y+S△ACD*B.y+S△ABD*C.y+S△BCD*A.y)/S;
z= (S△ABC*D.z+S△ACD*B.z+S△ABD*C.z+S△BCD*A.z)/S;
半径大小R可以根据 方程 1.0/4*S△ABC*H= 1.0/4* S*R (依据四面体体积相等) 解得
细节上,求三角形面积用了海伦公式,求ABC面上的高H用了H= | 向量AB*法向量n/| 法向量n | |
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<vector>using namespace std;#define all(x) (x).begin(), (x).end()#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)#define sqr(x) ((x)*(x))const double eps=1e-7;typedef long long ll;typedef pair<int, int> pii;const int INF =0x3f3f3f3f;struct Point{ double x,y,z; Point(){} Point(double x,double y,double z):x(x),y(y),z(z){}}A,B,C,D,O;typedef Point Vector;double R;Vector operator-(const Point &A,const Point &B){ return Vector(A.x-B.x,A.y-B.y,A.z-B.z);}Vector operator-(const Point &A){ return Vector(-A.x,-A.y,-A.z);}double Dot(Vector A,Vector B){ return (A.x*B.x+A.y*B.y+A.z*B.z);}Vector Cross(Vector a,Vector b){ return Vector( (a.y*b.z-a.z*b.y),-(a.x*b.z-b.x*a.z),(a.x*b.y-a.y*b.x) );}double Length(Vector a){ return sqrt( Dot(a,a));}double Helen(Point A,Point B,Point C)//海伦公式{ Vector AB=B-A;double c= Length(AB); Vector AC=C-A;double b= Length(AC); Vector BC=C-B;double a= Length(BC); double p=(a+b+c)/2; return sqrt( p*(p-a)*(p-b)*(p-c) );}bool solve(Point A,Point B,Point C,Point D){ Vector AB=B-A; Vector BC=C-B; Vector n= Cross(AB,BC); //法向量 double ret=Dot(D-A,n); if ( fabs(ret)<eps ) return false;//四点共面 double S=Helen(A,B,C ); O.x+= S*D.x; O.y+= S*D.y; O.z+= S*D.z; return true;}void getRandXYZ(){ Vector AB=B-A; Vector BC=C-B; Vector n= Cross(AB,BC); Vector AD=D-A; if(Dot(AD,n)<0) n=-n; double h= Dot(AD,n)/Length(n); double V4= h*Helen(A,B,C); double s=0; s+=Helen(A,B,C); s+=Helen(A,B,D); s+=Helen(A,C,D); s+=Helen(B,C,D); R=V4/s;//半径求得 O.x/=s;//球心坐标求得 O.y/=s; O.z/=s;}int main(){ while(~scanf("%lf%lf%lf",&A.x,&A.y,&A.z)) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf",&B.x,&B.y,&B.z,&C.x,&C.y,&C.z,&D.x,&D.y,&D.z ); memset(&O,0,sizeof O); if(!solve(A,B,C,D) ) { puts("O O O O"); continue; } solve(A,B,D,C); solve(A,C,D,B); solve(B,C,D,A); getRandXYZ(); printf("%.4f %.4f %.4f %.4f\n",O.x,O.y,O.z,R); } return 0;}
0 0
- hdu 5733 tetrahedron 求四面体内切球球心坐标及半径大小
- hdu5733 tetrahedron (求四面体内切球球心+点面距)
- HDU 5733 tetrahedron (求四面体内切球模板)
- 【HDU5733 2016 Multi-University Training Contest 1K】【计算几何 公式做法】tetrahedron 四面体内切球圆心与半径
- HDU 573 tetrahedron 三维计算几何(叉积, 四面体内切球)
- 2016 Multi-University Training Contest 1 1011 hdu 5733 四面体内切球
- 四面体内接圆_______tetrahedron( hdu 5733 2016多校第一场 )
- HDU 5733 tetrahedron
- 多校&&HDU.5733 tetrahedron
- HDU 5733 tetrahedron
- HDU BugZhu抽抽抽!! 知道三点坐标,求三角形面积,外接圆面积,半径
- 已知圆上三点坐标求圆心和半径
- HDU-5733-tetrahedron-计算几何
- BugZhu抽抽抽!!(已知三角形三点坐标,求外接圆半径及三角面积)
- 1206. Stacking Cylinders(几何题,求相切球的球心)
- sizeof求结构体内存大小
- 已知三点坐标,求外接圆圆心坐标与半径。
- 已知两点坐标和半径求圆心坐标程序C++
- js总结
- 学生信息系统
- HDU1426 Sudoku Killer(DFS暴力)
- js中window.onload添加事件
- Android自定义ProgressDialog
- hdu 5733 tetrahedron 求四面体内切球球心坐标及半径大小
- HDU 1067 Gap(哈希+bfs)
- css3新增选择器
- thinkphp中去掉index.php
- linux命令学习笔记
- LeetCode-122:Best Time to Buy and Sell Stock II
- OpenCV对图像的性能测试
- Android广播receiver
- C#基础-4:结构