zoukankan      html  css  js  c++  java
  • HDU5733 tetrahedron

    计算几何题 给出四个点 求这四个点构成三棱锥的内切球的三维坐标和半径

    先判断这个四个点是否共面 共面就直接输出O O O O 然后就用公式啦

    注意scanf的时候要用%lf 最开始用的%f就各种出现nan和inf

    这里贴个链接公式的链接 http://www.docin.com/p-504197705.html?qq-pf-to=pcqq.c2c

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 typedef unsigned long long ull;
     5 
     6 class point{
     7 public:
     8     double x;
     9     double y;
    10     double z;
    11     point(double xx = 0, double yy = 0, double zz = 0){
    12         x = xx;
    13         y = yy;
    14         z = zz;
    15     }
    16 };
    17 
    18 point operator -(point a, point b){
    19     return point(a.x - b.x, a.y - b.y, a.z - b.z);
    20 }
    21 
    22 point cross_product(point a, point b){
    23     return point(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
    24 }
    25 
    26 double dot_product(point a, point b){
    27     return a.x * b.x + a.y * b.y + a.z * b.z;
    28 }
    29 
    30 double Herons_formula(double a, double b, double c){
    31     double p = (a + b + c) / 2;
    32     return sqrt(p * (p - a) * (p - b) * (p - c));
    33 }
    34 
    35 double dist(point a, point b){
    36     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z));
    37 }
    38 
    39 int main(){
    40     point A, B, C, D;
    41     point AB, AC, AD;
    42     double s1, s2, s3, s4;
    43     double ab, ac, ad, bc, bd, cd;
    44     double x, y, z, r;
    45     double V;
    46     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) != EOF){
    47         AB = A - B;
    48         AC = A - C;
    49         AD = A - D;
    50         V = abs(dot_product(cross_product(AB , AC), AD) / 6);
    51         if (V == 0){
    52             cout<<"O O O O"<<endl;
    53             continue;
    54         }
    55         ab = dist(A, B);
    56         ac = dist(A, C);
    57         ad = dist(A, D);
    58         bc = dist(B, C);
    59         bd = dist(B, D);
    60         cd = dist(C, D);
    61         s1 = Herons_formula(bc, bd, cd);
    62         s2 = Herons_formula(ac, ad, cd);
    63         s3 = Herons_formula(ab, ad, bd);
    64         s4 = Herons_formula(ab, ac, bc);
    65         x = (s1 * A.x + s2 * B.x + s3 * C.x + s4 * D.x) / (s1 + s2 + s3 + s4);
    66         y = (s1 * A.y + s2 * B.y + s3 * C.y + s4 * D.y) / (s1 + s2 + s3 + s4);
    67         z = (s1 * A.z + s2 * B.z + s3 * C.z + s4 * D.z) / (s1 + s2 + s3 + s4);
    68         r = (V * 3) / (s1 + s2 + s3 + s4);
    69         printf("%.4lf %.4lf %.4lf %.4lf
    ", x, y, z, r);
    70     }
    71     return 0;
    72 }
  • 相关阅读:
    C#中DateTime.Ticks属性及Unix时间戳转换
    SQL Server:统计数据库中每张表的大小
    SQL Server:统计数据库中每张表的大小
    SQL Server:统计数据库中每张表的大小
    SQL Server 2008 R2:快速清除日志文件的方法
    SQL Server 2008 R2:快速清除日志文件的方法
    SQL Server 2008 R2:快速清除日志文件的方法
    ACM_HDU 1231 最大连续子序列 (dp)_代码分析
    斑马难题Step by Step
    多种配置的分布式配置中心
  • 原文地址:https://www.cnblogs.com/Misuchii/p/10897095.html
Copyright © 2011-2022 走看看