码迷,mamicode.com
首页 > 其他好文 > 详细

空间四点体积

时间:2021-06-19 18:50:57      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:include   div   tor   ble   result   tps   return   code   main   

https://ac.nowcoder.com/acm/contest/11212/E

#include<bits/stdc++.h>

using namespace std;

// define a point class to store a point
class Point
{
public:
    double x;
    double y;
    double z;
    Point(double x, double y, double z);
};
// constructor
Point::Point(double x, double y, double z)
{
    this->x = x;
    this->y = y;
    this->z = z;
}

// the function based on the given equation
double cal_volume(Point a, Point b, Point c, Point d)
{
    // a-d
    Point p_ad(a.x-d.x, a.y-d.y, a.z-d.z);
    // b-d
    Point p_bd(b.x-d.x, b.y- d.y, b.z-d.z);
    // c-d
    Point p_cd(c.x-d.x, c.y-d.y, c.z-d.z);
    // (b-d)x(c-d)
    Point p_bd_cd(p_bd.y * p_cd.z - p_bd.z * p_cd.y, p_bd.z * p_cd.x - p_bd.x * p_cd.z, p_bd.x * p_cd.y - p_bd.y * p_cd.x);
    // final result
    double res = abs(p_ad.x * p_bd_cd.x + p_ad.y * p_bd_cd.y + p_ad.z * p_bd_cd.z) / 6.0;
    return res;
}

int main()
{
    // test
    double x,y,z;
    cin>>x>>y>>z;
    Point p1(x, y, z);
    cin>>x>>y>>z;
    Point p2(x, y, z);
    cin>>x>>y>>z;
    Point p3(x, y, z);
    cin>>x>>y>>z;
    Point p4(x, y, z);
    double v = cal_volume(p1, p2, p3, p4);
    printf("%.7lf\n",v);
}

 

空间四点体积

标签:include   div   tor   ble   result   tps   return   code   main   

原文地址:https://www.cnblogs.com/qq1415584788/p/14901402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!