tetrahedron

题意:

求解一个四面体的内切球。

解法:

首先假设内切球球心为$(x0,x1,x2)$,可以用$r = \frac{3V}{S_1+S_2+S_3+S_4}$得出半径,

这样对于四个平面列出三个方程,解得

$x_n = \sum_{i=0}^3{Ai_{x_n} \cdot S_i } / (S_1 + S_2 + S_3 + S_4)$

这样,即可得出内切球。

时间复杂度$O(1)$。

  1 #include <iostream>
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <cmath>
  5
  6 #define LD double
  7 #define sqr(x) ((x)*(x))
  8 #define eps 1e-13
  9
 10 using namespace std;
 11
 12 struct node
 13 {
 14     LD x,y,z;
 15     void scan()
 16     {
 17         scanf("%lf%lf%lf",&x,&y,&z);
 18     }
 19     void print()
 20     {
 21         printf("%.4lf %.4lf %.4lf\n",x,y,z);
 22     }
 23     LD length()
 24     {
 25         return sqrt(sqr(x)+sqr(y)+sqr(z));
 26     }
 27     node operator+(const node &tmp)
 28     {
 29         return (node){x+tmp.x,y+tmp.y,z+tmp.z};
 30     }
 31     node operator-(const node &tmp)
 32     {
 33         return (node){x-tmp.x,y-tmp.y,z-tmp.z};
 34     }
 35     node operator/(LD tmp)
 36     {
 37         return (node){x/tmp,y/tmp,z/tmp};
 38     }
 39     node operator*(LD tmp)
 40     {
 41         return (node){x*tmp,y*tmp,z*tmp};
 42     }
 43 };
 44
 45 node cross(node a,node b)
 46 {
 47     node ans;
 48     ans.x = a.y*b.z - b.y*a.z;
 49     ans.y = b.x*a.z - a.x*b.z;
 50     ans.z = a.x*b.y - b.x*a.y;
 51     return ans;
 52 }
 53
 54 LD dist(node a,node b)
 55 {
 56     return (b-a).length();
 57 }
 58
 59 LD dot(node a,node b)
 60 {
 61     return a.x*b.x + a.y*b.y + a.z*b.z;
 62 }
 63
 64 LD get_angle(node a,node b)
 65 {
 66     LD tmp = dot(a,b)/a.length()/b.length();
 67     return acos(tmp);
 68 }
 69
 70 node get_node(node A,node B,node C)
 71 {
 72     LD Lth = (B-A).length() + (C-A).length() + (C-B).length();
 73     cout << sqr(Lth-4) << endl;
 74     LD r = fabs(cross(B-A,C-A).length()) / Lth;
 75     cout << r*r << endl;
 76     node v1 = C-A;
 77     node v2 = B-A;
 78     node v = (v1+v2)/(v1+v2).length();
 79     LD d = (C-A).length()/2;
 80     LD L = sqrt(sqr(d)+sqr(r));
 81     v = v*L;
 82     return A+v;
 83 }
 84
 85 int main()
 86 {
 87     node A,B,C,D;
 88     while(~scanf("%lf%lf%lf",&A.x,&A.y,&A.z))
 89     {
 90         B.scan();
 91         C.scan();
 92         D.scan();
 93         if(fabs(dot(cross(B-A,C-A),D-A)) < eps)
 94         {
 95             puts("O O O O");
 96             continue;
 97         }
 98         LD S1 = fabs(cross(B-D,C-D).length())/2;
 99         LD S2 = fabs(cross(D-A,C-A).length())/2;
100         LD S3 = fabs(cross(B-A,D-A).length())/2;
101         LD S4 = fabs(cross(B-A,C-A).length())/2;
102         LD Ve = fabs(dot(cross(B-A,C-A),D-A))/6;
103         LD R = 3*Ve / ((S1+S2+S3+S4));
104         node ans;
105         ans.x = (S1*A.x + S2*B.x + S3*C.x + S4*D.x)/(S1+S2+S3+S4);
106         ans.y = (S1*A.y + S2*B.y + S3*C.y + S4*D.y)/(S1+S2+S3+S4);
107         ans.z = (S1*A.z + S2*B.z + S3*C.z + S4*D.z)/(S1+S2+S3+S4);
108         printf("%.4lf %.4lf %.4lf %.4lf\n",ans.x,ans.y,ans.z,R);
109     }
110     return 0;
111 }
112 /*
113 0 0 0 2 0 0 0 0 2 0 2 0
114 0 0 0 2 0 0 3 0 0 4 0 0
115 */

时间: 2024-11-03 21:52:45

tetrahedron的相关文章

hdu 5839 Special Tetrahedron 计算几何 求特殊四面体个数

Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 175    Accepted Submission(s): 64 Problem Description Given n points which are in three-dimensional space(without repetition).

hdu-5839 Special Tetrahedron(计算几何)

题目链接: Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description Given n points which are in three-dimensional space(without repetition). Please find out how many distinct Special Tetr

HDU 5839 Special Tetrahedron(计算几何)

传送门 Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 616    Accepted Submission(s): 258 Problem Description Given n points which are in three-dimensional space(without repetit

CF 166E Tetrahedron

E. Tetrahedron time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly. An ant is standing in the ve

Gym 100169E Tetrahedron Inequality

大致题意: 给出六条边,判断是否能组成四面体 分析: 四面体由四个三角形组成,所以每一条边肯定要符合三角形的任意两边大于第三边的性质.一开始以为这样判断就可以了,然而这题并没有这么简单. 如右图,有四个三角形,六条边,但是并不是四面体 如下图,先选择五条边(绿色的五条边),然后展开成一个平面,三角形ABC和三角形ACD不重叠(重叠),此时只要将三角形ABC绕着AC轴旋转,BD即第六条边.所以展开成平面可求除最大值(最小值) #include <iostream> #include <cs

【HDU 5839】Special Tetrahedron(计算几何)

空间的200个点,求出至少四边相等,且其余两边必须不相邻的四面体的个数. 用map记录距离点i为d的点有几个,这样来优化暴力的四重循环. 别人的做法是枚举两点的中垂面上的点,再把到中点距离相等的点找出来,n^3的样子. 还要注意四个点共面的情况. 共面判断就是用叉乘计算出ijk三点所在面的法向量,然后判断il向量是否和法向量垂直,是则共面. #include <cstdio> #include <cstring> #include <algorithm> #includ

Codeforces Round #113 (Div. 2) E. Tetrahedron

题目链接:http://codeforces.com/problemset/problem/166/E 题意:给你一个四面体,从最上面那个顶点出发,走n步之后回到起点的方法有多少种.状态转移很简单dp[i][j] += dp[i-1][k](k != j); 但是n很大,这样做会超时,于是用矩阵快速幂来加速.A矩阵为0 1 1 1 1 0 1 1  1 1 0 1  1 1 1 0 #include <cstdio> #include <cstring> #include <

HDU 5839 Special Tetrahedron

暴力水过,数据水. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue>

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不相邻. 暴力4重循环,但是在第3重循环的时候需要判断是否是等腰三角形,这便是一个剪枝.在第4重循环的时候判断4点是否共面 (叉乘), 5或者6边相等就+1,4边相等就判断另外两边是否相交就行了. 赛后过的,觉得自己还是太菜了. 1 //#pragma comment(linker, "/STACK: