Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<cmath>
- using namespace std;
- class Polygone
- {
- private:
- vector<Point2D> v;
- public:
- explicit Polygone(const std::vector<Point2D>& points) {
- v = points;
- }
- double area() const {
- double s = 0;
- for (unsigned int i = 1; i < v.size() - 1; ++i) {
- 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()));
- }
- return s / 2;
- }
- unsigned int size() const {
- return v.size();
- }
- Point2D vertex(unsigned int N) const {
- return v[N];
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement