NikitaShigaev

Untitled

Apr 29th, 2020
684
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<vector>
  3. #include<cmath>
  4. using namespace std;
  5.  
  6. class Polygone
  7. {
  8. private:
  9.     vector<Point2D> v;
  10. public:
  11.     explicit Polygone(const std::vector<Point2D>& points) {
  12.         v = points;
  13.     }
  14.  
  15.     double area() const {
  16.         double s = 0;
  17.         for (unsigned int i = 1; i < v.size() - 1; ++i) {
  18.             s += abs((v[i].x() - v[0].x()) * (v[i + 1].y() - v[0].y()) - (v[i].y() - v[0].y()) * (v[i + 1].x() - v[0].x()));
  19.         }
  20.         return s / 2;
  21.     }
  22.  
  23.     unsigned int size() const {
  24.         return v.size();
  25.     }
  26.  
  27.     Point2D vertex(unsigned int N) const {
  28.         return v[N];
  29.     }
  30. };
RAW Paste Data