Advertisement
Hippskill

Untitled

Jan 19th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include<stdio.h>
  3. #include<iostream>
  4. #include<vector>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<memory.h>
  8. #include<map>
  9. #include<set>
  10. #include<queue>
  11. #include<list>
  12. #include<sstream>
  13. #include<cstring>
  14. #include<numeric>
  15. #include<limits.h>
  16. using namespace std;
  17.  
  18.  
  19. bool doubleEqual(double a, double b) {
  20.     return fabs(a - b) < 1e-9;
  21. }
  22.  
  23. bool doubleLess(double a, double b) {
  24.     return a < b && !doubleEqual(a, b);
  25. }
  26.  
  27. bool doubleLessOrEqual(double a, double b) {
  28.     return a < b || doubleEqual(a, b);
  29. }
  30.  
  31.  
  32. double mySqrt(double a) {
  33.     if (doubleLess(a, 0)) {
  34.         throw "sqrt(-1)";
  35.     }
  36.     if (a < 0) return 0;
  37.     return sqrt(a);
  38. }
  39.  
  40. double sqr(double a) {
  41.     return a * a;
  42. }
  43.  
  44. struct point {
  45. private: double x, y;
  46. public:
  47.     point() : x(0), y(0) {}
  48.     point(double x, double y) : x(x), y(y) {}
  49.  
  50.     void scan() {
  51.         scanf("%lf%lf", &x, &y);
  52.     }
  53.  
  54.     point operator+ (const point & P) const {
  55.         return point(x + P.x, y + P.y);
  56.     }
  57.  
  58.     point operator- (const point & P) const {
  59.         return point(x - P.x, y - P.y);
  60.     }
  61.  
  62.     point operator/ (double k) const {
  63.         return point(x / k, y / k);
  64.     }
  65.  
  66.     point operator*(double k) const {
  67.         return point(x * k, y * k);
  68.     }
  69.  
  70.     bool operator<(const point & P) const {
  71.         if (x != P.x) return x < P.x;
  72.         return y < P.y;
  73.     }
  74.  
  75.     double operator% (const point & P) const {
  76.         return x * P.x + y * P.y;
  77.     }
  78.  
  79.     double operator*(const point & p) const {
  80.         return x * p.y - y * p.x;
  81.     }
  82.  
  83.     double length() const {
  84.         return mySqrt(*this % *this);
  85.     }
  86.  
  87.     double val() {
  88.         return mySqrt(x * x + y * y);
  89.     }
  90.  
  91.     double dist(const point & P) const {
  92.         point r = P - *this;
  93.         return  r.val();
  94.     }
  95.  
  96.     point normalize(double k = 1) const
  97.     {
  98.         double len = length();
  99.         if (doubleEqual(len, 0)) {
  100.             if (doubleEqual(k, 0)) {
  101.                 return point();
  102.             }
  103.             //throw "zero-size vector";
  104.         }
  105.         return *this * (k / len);
  106.     }
  107.  
  108.     point getH(const point & A, const point & B) const {
  109.         point C = *this;
  110.         point v = B - A;
  111.         point u = C - A;
  112.         double k = v % u / v.length();
  113.         v = v.normalize(k);
  114.         point H = A + v;
  115.         return H;
  116.     }
  117.  
  118.     bool isOnLine(const point & A, const point & B) const {
  119.         return doubleEqual((A - *this) * (B - *this), 0);
  120.     }
  121.  
  122.     bool isInSegment(const point & A, const point & B) const {
  123.         return isOnLine(A, B) && doubleLessOrEqual((A - *this) % (B - *this), 0);
  124.     }
  125.  
  126. };
  127.  
  128. double triangleArea(point & A, point & B, point & C) {
  129.     return abs((A - B) * (C - B)) * 0.5;
  130. }
  131.  
  132.  
  133. double triangleArea(point & A, point & B, point & C) {
  134.     return abs((A - B) * (C - B)) * 0.5;
  135. }
  136.  
  137.  
  138. double area(vector<point> P) {
  139.     point M = (P[0] + P[2]) / 2;
  140.     double s = triangleArea(M, P[0], P[P.size() - 1]);
  141.     for (int i = 1; i < P.size(); i++) {
  142.         s += triangleArea(M, P[i], P[i - 1]);
  143.     }
  144.     return s;
  145. }
  146.  
  147.  
  148. int main(){
  149.     // чтение точек//
  150.    
  151.  
  152.     return 0;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement