zoukankan      html  css  js  c++  java
  • hdu 5733 tetrahedron 四面体内切球球心公式

    tetrahedron

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 889    Accepted Submission(s): 382


    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
     
    题意:给你四个点的坐标,判断是否有内切圆,如果有内切圆的话,输出内切圆圆心的坐标和半径;
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <map>
    #include <vector>
    #include <queue>
    #include <cstring>
    #include <string>
    #include <algorithm>
    using namespace std;
    typedef  long long  ll;
    typedef unsigned long long ull;
    #define MM(a,b) memset(a,b,sizeof(a));
    #define inf 0x7f7f7f7f
    #define FOR(i,n) for(int i=1;i<=n;i++)
    #define CT continue;
    #define PF printf
    #define SC scanf
    const int mod=1000000007;
    const int N=1e6+100;
    int n,m,c[N],pre[N],sum[N],a[N],ans[N];
    
    struct Point{
      ll x,y,z;
      void read()
      {
          scanf("%lld%lld%lld",&x,&y,&z);
      }
    }p[6];
    
    Point operator-(Point a,Point b)
    {
       return (Point){b.x-a.x,b.y-a.y,b.z-a.z};
    }
    
    double dis(Point a)
    {
       return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
    }
    
    Point cross(Point a,Point b)
    {
        return (Point){a.y*b.z-b.y*a.z,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x};
    }
    
    double dot(Point a,Point b)
    {
        return a.x*b.x+a.y*b.y+a.z*b.z;
    }
    
    double pointtoface(Point c,Point a,Point b,Point d)
    {
        Point m=cross(b-a,d-a);
        return dot(m,c-a)/dis(m);
    }//三维几何中点到面的距离利用 向量a*向量b=|a|*|b|cos(ang)
    
    int main()
    {
        double s[5];
        while(~scanf("%lld%lld%lld",&p[1].x,&p[1].y,&p[1].z))
        {
            p[2].read();p[3].read();p[4].read();
            if(dot(cross(p[2]-p[1],p[3]-p[1]),p[4])==0) {printf("O O O O
    ");CT;}
            double ts=0;
            s[1]=dis(cross(p[3]-p[2],p[4]-p[2]))/2;
            s[2]=dis(cross(p[3]-p[1],p[4]-p[1]))/2;
            s[3]=dis(cross(p[2]-p[1],p[4]-p[1]))/2;
            s[4]=dis(cross(p[3]-p[1],p[2]-p[1]))/2;
            for(int i=1;i<=4;i++) ts+=s[i];
    
            double h=pointtoface(p[3],p[1],p[2],p[4]);
            double r=fabs(s[3]/ts*h);
    
            double x=(s[1]*p[1].x+s[2]*p[2].x+s[3]*p[3].x+s[4]*p[4].x)/ts;
            double y=(s[1]*p[1].y+s[2]*p[2].y+s[3]*p[3].y+s[4]*p[4].y)/ts;
            double z=(s[1]*p[1].z+s[2]*p[2].z+s[3]*p[3].z+s[4]*p[4].z)/ts;
    
            printf("%.4f %.4f %.4f %.4f
    ",x,y,z,r);
        }
        return 0;
    }
    

      内切球坐标公式:http://www.docin.com/p-504197705.html?qq-pf-to=pcqq.c2c

    这道题目了解下内切球球心公式就好,其他没有什么难的

  • 相关阅读:
    字符串复习笔记
    构造
    网络流复习笔记
    LCT学习笔记
    省选前的数据结构训练
    在windows安装并启动测试kafka
    Scala 原生操作MySQL
    Scala基础语法
    ORACLE查出表所有的触发器及触发器详细信息
    转载二,JAVA面试题
  • 原文地址:https://www.cnblogs.com/smilesundream/p/5754917.html
Copyright © 2011-2022 走看看