(HDU 5733) tetrahedron <几何公式>
2017-01-07 19:57
267 查看
tetrahedron
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.
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
Recommend
wange2014
题意:
给你空间中四个点,若形成四面体则求出四面体内切圆的圆心坐标和半径。
分析:
就是一个几何公式题:
首先可以用向量叉乘求出四个面的面积s1,s2,s3,s4和四面体的体积V,如果V=0说明这四个点共面不能形成四面体,否则由r*(s1+s2+s3+s4)/3=V得到内切球半径r=3*v/(s1+s2+s3+s4),之后根据
x=(x1*s1+x2*s2+x3*s3+x4*s4)/(s1+s2+s3+s4)
y=(y1*s1+y2*s2+y3*s3+y4*s4)/(s1+s2+s3+s4)
z=(z1*s1+z2*s2+z3*s3+z4*s4)/(s1+s2+s3+s4)
求出内切球球心坐标即可
AC代码:
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.
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
Recommend
wange2014
题意:
给你空间中四个点,若形成四面体则求出四面体内切圆的圆心坐标和半径。
分析:
就是一个几何公式题:
首先可以用向量叉乘求出四个面的面积s1,s2,s3,s4和四面体的体积V,如果V=0说明这四个点共面不能形成四面体,否则由r*(s1+s2+s3+s4)/3=V得到内切球半径r=3*v/(s1+s2+s3+s4),之后根据
x=(x1*s1+x2*s2+x3*s3+x4*s4)/(s1+s2+s3+s4)
y=(y1*s1+y2*s2+y3*s3+y4*s4)/(s1+s2+s3+s4)
z=(z1*s1+z2*s2+z3*s3+z4*s4)/(s1+s2+s3+s4)
求出内切球球心坐标即可
AC代码:
#include<cstdio> #include<iostream> #include<cmath> using namespace std; #define eps 1e-8 struct node { double x,y,z; }a,b,c,d,ans; double get(node a,node b,node c) { double x1=b.x-a.x,y1=b.y-a.y,z1=b.z-a.z; double x2=c.x-a.x,y2=c.y-a.y,z2=c.z-a.z; double d1=y1*z2-y2*z1; double d2=x1*z2-x2*z1; double d3=x1*y2-x2*y1; return sqrt(d1*d1+d2*d2+d3*d3)*0.5; } double Get(node a,node b,node c,node d) { double x1=b.x-a.x,y1=b.y-a.y,z1=b.z-a.z; double x2=c.x-a.x,y2=c.y-a.y,z2=c.z-a.z; double x3=d.x-a.x,y3=d.y-a.y,z3=d.z-a.z; double ans=x1*(y2*z3-y3*z2)-y1*(x2*z3-x3*z2)+z1*(x2*y3-x3*y2); return abs(ans)/6.0; } int main() { while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.z,&b.x,&b.y,&b.z,&c.x,&c.y,&c.z,&d.x,&d.y,&d.z)) { double s1,s2,s3,s4,V; V=Get(a,b,c,d); s1=get(b,c,d); s2=get(a,c,d); s3=get(a,b,d); s4=get(a,b,c); double t=s1+s2+s3+s4; if(V<eps) { printf("O O O O\n"); continue; } ans.x=(s1*a.x+s2*b.x+s3*c.x+s4*d.x)/t; ans.y=(s1*a.y+s2*b.y+s3*c.y+s4*d.y)/t; ans.z=(s1*a.z+s2*b.z+s3*c.z+s4*d.z)/t; double r=V*3.0/t; printf("%.4lf %.4lf %.4lf %.4lf\n",ans.x,ans.y,ans.z,r); } }
相关文章推荐
- hdu 5733 tetrahedron(2016 Multi-University Training Contest 1——几何公式题)
- 三维计算几何模板 hdu 5733 tetrahedron(不知为何WA)
- hdu 4613 Points<计算几何>
- (HDU 5733)2016 Multi-University Training Contest 1 tetrahedron(几何)
- 2016 Multi-University Training Contest 1-1011---HDU 5733 tetrahedron(计算几何)
- HDU 5733 tetrahedron(空间计算几何)
- (HDU 5738) <计算几何 ,在n个点中找所有共线的集合> 2016 Multi-University Training Contest 2
- HDU 5733 tetrahedron (2016 Multi-University Training Contest 1 计算几何)
- hdu 5733 tetrahedron(2016 Multi-University Training Contest 1计算几何)
- HDU 5733 tetrahedron(计算几何)
- HDU 5733 tetrahedron(计算几何)
- HDU-5733-tetrahedron-计算几何
- HDU 5733 tetrahedron(三维几何)
- hdu 1700 Points on Cycle<计算几何>
- HDU 5733 tetrahedron(计算几何)【多校联合】
- HDU 5733 tetrahedron(几何——四面体内心/体积/内切圆)
- hdu--5128--计算几何<算不上.暴力模拟> && hdu--5131--初级cmp
- hdu 3328 Flipper <stack>
- hdu 1075 What Are You Talking About< map<string,string> >
- hdu 2553 N皇后问题<java>