Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.64 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <iomanip>
  6. #include <iostream>
  7. #include <typeinfo>
  8. #include <cassert>
  9. class Line;
  10. const double EPS__ = 1e-6;
  11. struct Point {
  12.     double x;
  13.     double y;
  14.     Point () {}
  15.     Point (double a, double b) {
  16.         x = a;
  17.         y = b;
  18.     }
  19.    
  20.     Point& operator = (const Point & another) {
  21.         x = another.x;
  22.         y = another.y;
  23.         return *this;
  24.     }
  25.     const Point operator + (const Point & another) const {
  26.         Point temp;
  27.         temp.x = (fabs(x + another.x) < EPS__) ? 0 : x + another.x;
  28.         temp.y = (fabs(y + another.y) < EPS__) ? 0 : y + another.y;
  29.         return temp;
  30.     }
  31.     const Point operator - () const {
  32.         Point temp;
  33.         temp.x = -(x);
  34.         temp.y = -(y);
  35.         return temp;
  36.     }
  37.     const Point operator - (const Point & another) const {
  38.         return (*this + (-another));
  39.     }
  40.     const Point operator * (const double & a) const {
  41.         Point temp;
  42.         temp.x = a * x;
  43.         temp.y = a * y;
  44.         return temp;
  45.     }
  46.     const Point operator / (const double & a) const {
  47.         Point temp;
  48.         temp.x = x / a;
  49.         temp.y = y / a;
  50.         return temp;
  51.     }
  52.     bool operator == (const Point & another) const {
  53.         return ((fabs(x - another.x) < EPS__) && (fabs(y - another.y) < EPS__));
  54.     }
  55.     bool operator != (const Point& another) const {
  56.         return !(*this == another);
  57.     }
  58.     const Point rotate (const Point center, double angle) const {
  59.          Point temp1, temp;
  60.          temp1 =  *this - center;
  61.          temp.x = center.x + temp1.x * (cos(angle)) - temp1.y * (sin(angle));
  62.          if (fabs(temp.x) < EPS__) temp.x = 0;
  63.          temp.y = center.y + temp1.x * (sin(angle)) + temp1.y * (cos(angle));
  64.           if (fabs(temp.y) < EPS__) temp.y = 0;
  65.          return temp;
  66.     }
  67.     const Point scale(const Point center, double coefficient) const {
  68.         Point temp;
  69.         temp.x = center.x + (x - center.x) * coefficient;
  70.             if (fabs(temp.x) < EPS__) temp.x = 0;
  71.         temp.y = center.y + (y - center.y) * coefficient;
  72.             if (fabs(temp.y) < EPS__) temp.y = 0;
  73.         return temp;
  74.     }
  75.     const Point reflex(const Point center) {
  76.         Point temp;
  77.         temp.x = 2 * center.x - x;
  78.         temp.y = 2 * center.y - y;
  79.         return temp;
  80.     }
  81.     const double distance(const Point& a) const {
  82.         return sqrt((x - a.x)*(x - a.x) + (y - a.y)*(y - a.y));
  83.     }
  84.    
  85.     const double length () const {
  86.         return sqrt(double(x * x + y * y));
  87.     }
  88.     const double length2 () const {
  89.         return (x * x + y * y);
  90.     }
  91.     const Point reflex(Line axis);
  92. };
  93.  
  94. const Point operator * (const double & a, const Point & b) {
  95.     Point temp;
  96.     temp.x = a * b.x;
  97.     temp.y = a * b.y;
  98.     return temp;
  99. }    
  100.  
  101. std::ostream& operator<<(std::ostream& os, const Point& n) {
  102.     double a = n.x;
  103.     double b = n.y;
  104.     os << '(' << a << ", " << b << ')';
  105.     return os;
  106. }
  107.  
  108. class Line {
  109. private:
  110.     double A;
  111.     double B;
  112.     double C;
  113. public:
  114.     Line() {}
  115.     Line(Point a, Point b) {
  116.         if (a.x * b.y == a.y * b.x) {
  117.             C = 0;
  118.             A = a.y - b.y;
  119.             B = -a.x + b.x;
  120.             if (A < 0) {
  121.                 A = -A;
  122.                 B = -B;
  123.                 C = -C;
  124.             }
  125.             double r = sqrt(A*A + B*B);
  126.             A/= r;
  127.             B/= r;
  128.         } else {
  129.             C =  -1;
  130.             A = (b.y - a.y)/(a.x * b.y - b.x * a.y);
  131.             B = (a.x - b.x)/(a.x * b.y - b.x * a.y);
  132.             if (A < 0) {
  133.                 A = -A;
  134.                 B = -B;
  135.                 C = -C;
  136.             }
  137.             double r = sqrt(A*A + B*B);
  138.             A/= r;
  139.             B/= r;
  140.             C/= r;
  141.            
  142.         }
  143.     }
  144.     Line(Point a, double coof) {
  145.         Point temp;
  146.         temp.x = a.x + 1;
  147.         temp.y = a.y + coof;
  148.         *this = Line(a, temp);
  149.     }
  150.     Line(double k, double b) {
  151.         Point temp (0, b);
  152.         *this = Line(temp, k);
  153.     }
  154.     bool isHigher(const Point &point) const {
  155.         return ((A != 0) && -(B * point.y + C) / A >= point.x);
  156.     }
  157.        
  158.     friend std::ostream& operator<<(std::ostream& os, const Line& n);
  159.     bool operator == (const Line & another) const {
  160.         return (A == another.A && B == another.B && C == another.C);
  161.     }
  162.     bool operator != (const Line & another) const {
  163.         return!(*this == another);
  164.     }  
  165.     Point normal() const {
  166.         Point temp(A / sqrt(A * A + B * B), B / sqrt(A * A + B * B));
  167.         return temp;
  168.     }
  169.     friend const Point Point::reflex(Line axis);
  170. };
  171.  
  172. const Point Point::reflex(Line axis) {
  173.     Point temp;
  174.     double xq = (axis.A * x + axis.B * y + axis.C) / (axis.A*axis.A + axis.B * axis.B);
  175.     temp.x = x - 2 * xq * axis.A;
  176.     temp.y = y - 2 * xq * axis.B;
  177.     return temp;
  178. }
  179. std::ostream& operator<<(std::ostream& os, const Line& n) {
  180.     double a = n.A;
  181.     double b = n.B;
  182.     double c = n.C;
  183.     os << a << "*x + " << b <<"*y + " << c << " = 0";
  184.     return os;
  185. }
  186. class Shape {
  187. public:
  188.     virtual ~Shape(){}
  189.  
  190.     virtual bool operator ==(const Shape& another) const = 0;
  191.     virtual bool operator !=(const Shape& another) const = 0;
  192.  
  193.     virtual double perimeter() const = 0;
  194.     virtual double area() const = 0;
  195.     virtual bool isCongruentTo(const Shape& another) const = 0;
  196.     virtual bool isSimilarTo(const Shape& another) const = 0;
  197.     virtual bool containsPoint(const Point& p) const = 0;
  198.  
  199.     virtual void rotate(Point center, double angle) = 0;
  200.     virtual void reflex(Point center) = 0;
  201.     virtual void reflex(Line axis) = 0;
  202.     virtual void scale(Point center, double coefficient) = 0;
  203. };
  204.  
  205. class Vector {
  206. private:
  207.     double x;
  208.     double y;
  209. public:
  210.     Vector() {}
  211.     Vector(const Point &first, const Point &second) {
  212.         x = second.x - first.x;
  213.         y = second.y - first.y;
  214.     }
  215.     Vector (const Point& A) {
  216.         x = A.x;
  217.         y = A.y;
  218.     }
  219.     const double det (const Vector &A) const {
  220.         return (x * A.y - y * A.x);
  221.     }
  222.     const double operator * (const Vector &A) const {
  223.         return (x * A.x + y * A.y);
  224.     }
  225.     const double length () const {
  226.         return sqrt(x * x + y * y);
  227.     }
  228.     const double sqrlength() const {
  229.         return (x * x + y * y);
  230.     }
  231.     const double angle(const Vector& A) const {
  232.         return ( A * (*this) / (A.length() * length()));
  233.     }
  234. };
  235.  
  236. class Ellipse:public Shape {
  237. protected:
  238.     Point F1;
  239.     Point F2;
  240.     double sum;
  241.     double a;
  242.     double b;
  243. public:
  244.     Ellipse() {}
  245.     Ellipse(Point& f1, Point & f2, double Sum) {
  246.         F1 = f1;
  247.         F2 = f2;
  248.         sum = Sum;
  249.         a = Sum / 2;
  250.         Vector xq (f1, f2);
  251.         b = sqrt(a * a - xq.sqrlength() / 4);
  252.     }
  253.     double area () const {
  254.         return M_PI * a * b;
  255.     }
  256.     double perimeter() const{
  257.         return M_PI * (3 * (a + b) - sqrt((3 * a + b) * (3 * b + a)));
  258.     }
  259.     bool operator == (const Shape& another) const {
  260.             const Ellipse* other = dynamic_cast<const Ellipse*>(&another);
  261.             if (!other) {
  262.                 return false;
  263.         }
  264.         return (focuses() == other->focuses() && sum == other->sum);
  265.     }
  266.     bool operator !=(const Shape& another) const {
  267.         return !(*this == another);
  268.     }
  269.     bool isCongruentTo(const Shape& another) const{
  270.         const Ellipse* other = dynamic_cast<const Ellipse*>(&another);
  271.             if (!other) {
  272.                 return false;
  273.         }
  274.         return (a == other->a && b == other->b);
  275.     }
  276.     bool isSimilarTo(const Shape& another) const {
  277.         const Ellipse* other = dynamic_cast<const Ellipse*>(&another);
  278.            
  279.             if (!other) {
  280.                 return false;
  281.         }
  282.             return (eccentricity() == other->eccentricity());
  283.     }
  284.     bool containsPoint(const Point& point) const {
  285.         return (F1.distance(point) + F2.distance(point) < sum);
  286.     }
  287.     std::pair<Point,Point> focuses() const {
  288.         return (std::make_pair(F1, F2));
  289.     }
  290.     const Point center() const {
  291.         return (F1 + F2) / 2;
  292.     }
  293.     double eccentricity() const {
  294.         return (sqrt(1 - b * b / (a * a)));
  295.     }
  296.    
  297.     std::pair<Line, Line> directrixes() {
  298.         Point A = F1.scale(center(), a / eccentricity());
  299.         Line D1(A, (F1.y - F2.y) / (F2.x - F1.x));
  300.         Point B = F2.scale(center(), a / eccentricity());
  301.         Line D2(B, (F1.y - F2.y) / (F2.x - F1.x));
  302.         return (std::make_pair(D1, D2));
  303.     }
  304.     void rotate(Point center, double angle) {
  305.         F1 = F1.rotate(center, angle);
  306.         F2 = F2.rotate(center, angle);
  307.     }
  308.     void reflex(Point center) {
  309.         F1 = F1.reflex(center);
  310.         F2 = F2.reflex(center);
  311.     }
  312.     void reflex(Line axis) {
  313.         F1 = F1.reflex(axis);
  314.         F2 = F2.reflex(axis);
  315.     }
  316.     void scale(Point center, double coefficient) {
  317.         F1 = F1.scale(center, coefficient);
  318.         F2 = F2.scale(center, coefficient);
  319.         sum *= fabs(coefficient);
  320.         a *= fabs(coefficient);
  321.         b *= fabs(coefficient);
  322.     }
  323.     friend std::ostream& operator<<(std::ostream& os, const Ellipse& n);
  324. };
  325. std::ostream& operator<<(std::ostream& os, const Ellipse& n) {
  326.     os << n.focuses().first << ' ' << n.focuses().second << ' ' << n.sum << std::endl;
  327.     return os;
  328. }
  329.  
  330. class Circle:public Ellipse {
  331. public:
  332.     Circle() {}
  333.     Circle(Point &center, double radius) : Ellipse(center, center, 2*radius){}
  334.     double radius() const{
  335.         return (sum / 2.);
  336.     }
  337.     double perimeter() const {
  338.         return 2 * M_PI * radius();
  339.     }
  340.     double area() const {
  341.         return M_PI * radius() * radius();
  342.     }
  343.  
  344. };
  345.  
  346.  
  347. std::vector<int> z_function(std::vector<Point> array) {
  348.     int n = array.size();
  349.     std::vector<int> z(n);
  350.         for (int i = 1, l = 0, r = 0; i < n; ++i) {
  351.             if (i <= r) {
  352.                 z[i] = std::min (r - i + 1, z[i-l]);
  353.             }
  354.         while (i + z[i] < n && array[z[i]] == array[i + z[i]]) {
  355.             ++z[i];
  356.         }
  357.         if (i + z[i] - 1 > r) {
  358.             l = i;
  359.             r = i+z[i]-1;
  360.         }
  361.     }
  362.     return z;  
  363. }
  364.  
  365.  
  366. class Polygon:public Shape {
  367. protected:
  368.     std::vector<Point> vert;
  369.     void init(const Point& p) {
  370.         vert.push_back(p);
  371.     }
  372.     template <class... Args>
  373.     void init(const Point& p, Args... args) {
  374.         vert.push_back(p);
  375.         init(args...);
  376.     }
  377. public:
  378.     Polygon() {}
  379.     Polygon (const std::vector<Point>& vert2) :vert(vert2.begin(), vert2.end()){}
  380.     template<class... Args>
  381.     Polygon (Args... args) {
  382.         init(args...);
  383.     }
  384.     std::vector<Point> getVertices() {
  385.         return vert;
  386.     }
  387.     const int verticesCount() const {
  388.         return vert.size();
  389.     }
  390.      double area() const {
  391.         double ar = 0;
  392.         for (size_t i = 0; i < vert.size(); ++i) {
  393.             Vector S(vert[i]);
  394.             Vector S2(vert[(i + 1) % vert.size()]);
  395.             ar += S.det(S2);
  396.         }
  397.         return fabs(ar / 2);
  398.     }
  399.     double perimeter() const {
  400.         double P = 0;
  401.         for (size_t i = 0; i < vert.size(); ++i) {
  402.             Vector S(vert[i], vert[(i + 1) % vert.size()]);
  403.             P += S.length();
  404.         }
  405.         return P;
  406.     }
  407.     bool isConvex() const {
  408.         int k = 1;
  409.         int l = 0;
  410.        
  411.         for(size_t i = 0; i < vert.size(); ++i) {
  412.             Vector A(vert[i], vert[(i + 1) % vert.size()]);
  413.             Vector B(vert[(i + 1) % vert.size()], vert[(i + 2) % vert.size()]);
  414.             if (A.det(B) > 0) {
  415.                 k = 0;
  416.             }
  417.             if (A.det(B) < 0) {
  418.                 l = 1;
  419.             }
  420.         }
  421.         return !(k < l);
  422.     }
  423.     bool operator == (const Shape& another) const {
  424.         const Polygon* another2 = dynamic_cast<const Polygon*>(&another);
  425.         if (!another2) {
  426.             return false;
  427.         }
  428.         std::vector<Point> a = another2->vert;
  429.         std::vector<Point> b;
  430.         for (size_t i = 0; i < another2->vert.size(); ++i) {
  431.             b.push_back(another2->vert[another2->vert.size() - 1 - i]);
  432.         }
  433.         if (another2->vert.size() != vert.size()) {
  434.             return false;
  435.         } else {    
  436.             for (size_t i = 0; i < vert.size(); ++i) {
  437.                 a.push_back(vert[i]);
  438.             }
  439.             for (size_t i = 0; i < vert.size(); ++i) {
  440.                 a.push_back(vert[i]);
  441.             }
  442.             int n = a.size();
  443.             std::vector<int> z(n);
  444.             z = z_function(a);
  445.             for (size_t i = 0; i < 2 * vert.size(); ++i) {
  446.                 if (z[vert.size() + i] >= (int) vert.size()) {
  447.                     return true;
  448.                 }
  449.             }  
  450.             for (size_t i = 0; i < vert.size(); ++i) {
  451.                 b.push_back(vert[i]);
  452.             }
  453.             for (size_t i = 0; i < vert.size(); ++i) {
  454.                 b.push_back(vert[i]);
  455.             }
  456.             std::vector<int> y;
  457.             y = z_function(b);
  458.             for (size_t i = 0; i < 2 * vert.size(); ++i) {
  459.                 if (y[vert.size() + i] >= (int) vert.size()) {
  460.                     return true;
  461.                 }
  462.             }  
  463.         }
  464.         return false;
  465.     }  
  466.     bool operator !=(const Shape& another) const {
  467.         return !(*this == another);
  468.     }
  469.    
  470.     bool isCongruentTo(const Shape & another) const {
  471.         const Polygon* another2 = dynamic_cast<const Polygon*>(&another);
  472.         if (!another2) {
  473.             return false;
  474.         }
  475.         if (vert.size() != another2->vert.size()) {
  476.             return false;
  477.         }
  478.         int n = vert.size();
  479.        
  480.         std::vector <Point> another3;
  481.         for (int i = 0; i < n; ++i) {  
  482.             another3.push_back(another2->vert[n - 1 - i]);
  483.         }
  484.         for (int order = 0; order < 2; ++order) {
  485.             std::vector <Point> temp = (order) ? another3 : another2->vert;
  486.             for (int i = 0; i < n; ++i) {      
  487.                 std::vector <double> angles;
  488.                 std::vector <double> another_angles;
  489.                 std::vector <double> ratio;
  490.                 bool k = true;
  491.                 for (size_t j = 1; j < temp.size(); ++j) {
  492.                     Vector a (vert[j - 1], vert[(j)]);
  493.                     Vector b (temp[(i + j - 1) % n], temp[(i + j) % n]);
  494.                     ratio.push_back(a.sqrlength() / b.sqrlength());
  495.                     Polygon A(vert[(j - 1)], vert[j], vert[(j + 1) % n]);
  496.                     Polygon B(temp[(i + j  - 1) % n], temp[(i + j) % n], temp[(i + j  + 1) % n]);
  497.                     angles.push_back(fabs(A.area() / a.sqrlength()) < EPS__ ? 0 : (A.area() / a.sqrlength()));
  498.                     another_angles.push_back(fabs(B.area() / b.sqrlength()) < EPS__ ? 0 : (B.area() / b.sqrlength()));
  499.                 }
  500.                 for (size_t j = 0; j < angles.size(); ++j) {
  501.                     if (fabs(ratio[j] - 1) > EPS__ || (angles[j] - another_angles[j]) > EPS__) {
  502.                             k = false;
  503.                     }
  504.                 }
  505.                 if (k) {
  506.                     return true;
  507.                 }
  508.             }
  509.         }
  510.         return false;
  511.     }
  512.  
  513.     bool isSimilarTo(const Shape & another) const {
  514.         std::vector <Point> other_vert(vert.size());
  515.         double coefficient = another.perimeter() / perimeter();
  516.         for (size_t i = 0; i < vert.size(); ++i) {
  517.             other_vert[i] = vert[i] * coefficient;
  518.         }
  519.         Polygon other(other_vert);
  520.         return other.isCongruentTo(another);
  521.     }  
  522.    
  523.     bool containsPoint(const Point &point) const {
  524.         int k = 0;
  525.         for (size_t i = 0; i < vert.size(); ++i) {
  526.                 k += (std::max(vert[i].x, vert[(i+1) % vert.size()].x) <= point.x
  527.                         && std::max(vert[i].y, vert[(i + 1) % vert.size()].y) >= point.y
  528.                         && std::min(vert[i].y, vert[(i + 1) % vert.size()].y) < point.y);
  529.             }
  530.         return (k % 2);
  531.     }
  532.        
  533.     void reflex(Point center)  {
  534.         std::vector <Point> vect;
  535.         for (size_t i = 0; i < vert.size(); ++i) {
  536.             vect.push_back( 2 * center - vert[i] );
  537.         }
  538.         vert = vect;
  539.     }
  540.    
  541.     void rotate(Point center, double angle) {
  542.         std::vector <Point> vect;
  543.         for (size_t i = 0; i < vert.size(); ++i) {
  544.             vect.push_back(vert[i].rotate(center, angle));
  545.         }
  546.         vert = vect;
  547.     }
  548.     void reflex(Line axis)  {
  549.         std::vector <Point> vect;
  550.         for (size_t i = 0; i < vert.size(); ++i) {
  551.             vect.push_back( vert[i].reflex(axis) );
  552.         }
  553.         vert = vect;
  554.     }
  555.    
  556.     void scale(Point center, double coefficient)   {
  557.         std::vector <Point> vect;
  558.         for (size_t i = 0; i < vert.size(); ++i) {
  559.             vect.push_back(vert[i].scale(center, coefficient) );
  560.         }
  561.         vert = vect;
  562.     }
  563.    
  564.     friend std::ostream& operator<<(std::ostream& os, const Polygon& n);
  565. };
  566.  
  567. std::ostream& operator<<(std::ostream& os, const Polygon& n) {
  568.     for (size_t i = 0; i < n.vert.size(); ++i) {
  569.         os << n.vert[i] << ' ';
  570.     }
  571.     return os;
  572. }
  573.  
  574. class Rectangle : public Polygon {
  575. public:
  576.     Rectangle() {}
  577.      template<typename Type>
  578.     Rectangle(const Point &a, const Point &b, Type coef2) {
  579.         double coef = static_cast<double>(coef2);
  580.         vert.resize(4);
  581.         coef = (coef >= 1) ? coef : 1 / coef;
  582.         double proportion = (coef * coef) / (1 + coef * coef);
  583.         Point n = Line(a, b).normal();
  584.         Point d = b - a;
  585.         vert[0] = a;
  586.         vert[1] = a + proportion * d + (d.length() * coef / (1 + coef * coef)) * n;
  587.         vert[2] = b;
  588.         vert[3] = b - proportion * d - (d.length() * coef / (1 + coef * coef)) * n;
  589.     }
  590.     template<class... Args>
  591.     Rectangle(Args... args): Polygon(args...) {}
  592.     Rectangle(const std::vector<Point>& vert): Polygon(vert) {
  593.         assert(vert.size() == 4);
  594.     }
  595.     Point center() {
  596.         return ((vert[0] + vert[2]) / 2);
  597.     }
  598.     std::pair<Line, Line> diagonals() const  {
  599.         return std::make_pair(Line(vert[0], vert[2]), Line(vert[1], vert[3]));
  600.     };    
  601. };
  602.  
  603. class Square : public Rectangle {
  604. public:
  605.     Square() {}
  606.     Square(const Point& a, const Point& b): Rectangle(a, b, 1) {}
  607.    
  608.     const Circle circumscribedCircle() const {
  609.         Point center = (vert[0] + vert[2]) / 2;
  610.         double R = (vert[2] - vert[0]).length() / 2;
  611.         return Circle(center, R);
  612.     }
  613.    
  614.     const Circle inscribedCircle() const {
  615.         Point center = (vert[0] + vert[2]) / 2;
  616.         double r = (vert[1] - vert[0]).length() / 2;
  617.         return Circle(center, r);
  618.     }
  619. };
  620.  
  621. class Triangle :public Polygon {
  622. public:
  623.     Triangle() {}
  624.     template<class... Args>
  625.     Triangle(Args... args): Polygon(args...) {}
  626.     Triangle(const std::vector<Point>& vert): Polygon(vert) {
  627.         assert(vert.size() == 3);
  628.     }
  629.     const Point centroid() const {
  630.         return (vert[0] / 3 + vert[1] / 3 + vert[2] / 3);
  631.     }
  632.    
  633.     const Circle circumscribedCircle() const {
  634.         const  Point A = vert[0], B = vert[1], C = vert[2];
  635.         double a2 = (B - C).length2(), b2 = (C - A).length2(), c2 = (A - B).length2();
  636.         double xa = a2 * (b2 + c2 - a2), xb = b2 * (a2  + c2 - b2), xc = c2 * (a2 + b2 - c2);
  637.         double X = xa + xb + xc;
  638.         Point center = A * xa / X + B * xb / X + C * xc / X;
  639.         double R = (A - center).length();
  640.         return Circle(center, R);
  641.     }
  642.     const Circle inscribedCircle() const {
  643.         Point A = vert[0], B = vert[1], C = vert[2];
  644.         double a = (B - C).length(), b = (C - A).length(), c = (A - B).length();
  645.         double X = a + b + c;
  646.         Point center = A * a / X + B * b / X + C * c / X;
  647.         double r = 2 * area() / perimeter() ;
  648.         return Circle(center, r);
  649.     }
  650.    
  651.     const Point orthocenter() const {
  652.         Point A = vert[0], B = vert[1], C = vert[2];
  653.         double a2 = (B - C).length2(), b2 = (C - A).length2(), c2 = (A - B).length2();
  654.         double xa = (a2 + b2 - c2) * (a2 - b2 + c2), xb = (a2 + b2 - c2)* (-a2 + b2  + c2), xc = (a2 - b2 + c2) * (-a2 + b2 + c2);
  655.         double X = xa + xb + xc;
  656.         Point ort = A * xa / X + B * xb / X + C * xc / X;
  657.         return ort;
  658.     }
  659.    
  660.     const Line EulerLine() const {
  661.         return Line(centroid(), ninePointsCircle().center());
  662.     }
  663.    
  664.     const Circle ninePointsCircle() const {
  665.         Point center = (orthocenter() + circumscribedCircle().center() ) / 2.;
  666.         double R = circumscribedCircle().radius() / 2.;
  667.         return Circle(center, R);
  668.     }
  669. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement