CODE

#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <cmath>
using namespace std;
struct Point 
{ double x, y; }; double cross(const Point &A, const Point &B, const Point &C)
{ return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x); } double polygon_area(vector<Point>& v) { double area=0; auto it=v.begin(); for(;it<v.end();++it) { area+=cross({0,0},*it,*(it+1)); } return abs(area/2); } int main() { fstream fs("C:\\Documents and Settings\\Administrator\\桌面\\poly.txt"); Point tmp; vector<Point> v; while(!fs.eof()) { fs>>tmp.x>>tmp.y; v.push_back(tmp); } double area=polygon_area(v); cout<<"多边形面积为:"<<area<<endl; return 0; }

相关文章:

  • 2022-02-08
  • 2022-12-23
  • 2021-10-10
  • 2021-07-27
  • 2021-07-30
  • 2021-12-25
  • 2021-07-31
猜你喜欢
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2021-07-13
  • 2022-01-23
相关资源
相似解决方案