当前位置:   article > 正文

棱台体积的计算

棱台体积
  1. struct Point2d
  2. {
  3. double x;
  4. double y;
  5. Point2d(double xx, double yy): x(xx), y(yy){}
  6. };
  7. //计算任意多边形的面积,顶点按照顺时针或者逆时针方向排列
  8. double ComputePolygonArea(const vector<Point2d> &points)
  9. {
  10. int point_num = points.size();
  11. if(point_num < 3)return 0.0;
  12. double s = points[0].y * (points[point_num-1].x - points[1].x);
  13. for(int i = 1; i < point_num; ++i)
  14. s += points[i].y * (points[i-1].x - points[(i+1)%point_num].x);
  15. return fabs(s/2.0);
  16. }
  17. //计算体积
  18. // 1
  19. //V = — *(upArea+bottomArea + √(upArea*bottomArea) )
  20. // 3
  21. double ComputeVolume(double upArea,double bottomArea,double Height)
  22. {
  23. if(Height == 0||(upArea==0 && bottomArea==0))
  24. {
  25. returen 0.0;
  26. }
  27. retuen (Height*(upArea+bottomArea+sqrt(upArea*bottomArea)))/3;
  28. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/833728
推荐阅读
相关标签
  

闽ICP备14008679号