Advertisement
Guest User

J

a guest
Feb 25th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. struct Point {
  9.     double x, y;
  10.  
  11.     Point(double x0 = 0, double y0 = 0)
  12.     {
  13.         x = x0;
  14.         y = y0;
  15.     }
  16. };
  17.  
  18. istream & operator >> (istream & in, Point & P) {
  19.     in >> P.x >> P.y;
  20.     return in;
  21. }
  22.  
  23.  
  24. ostream & operator << (ostream & out, Point & P) {
  25.     out << P.x << " " << P.y;
  26.     return out;
  27. }
  28.  
  29.  
  30. struct Vector {
  31.     double x, y;
  32.  
  33.     Vector(double x0, double y0) {
  34.         x = x0;
  35.         y = y0;
  36.     }
  37.  
  38.     Vector(Point A = Point(0, 0), Point B = Point(0, 0)) {
  39.         x = B.x - A.x;
  40.         y = B.y - A.y;
  41.     }
  42. };
  43.  
  44.  
  45. double getDist(Point A, double a, double b, double c) {
  46.     return fabs((a * A.x + b * A.y + c)) / hypot(a, b);
  47. }
  48.  
  49.  
  50. double* getBisectorEquation(Point B, Point A, Point C) {
  51.     // bac bisector
  52.     Vector AB = Vector(A, B);
  53.     Vector AC = Vector(A, C);
  54.     double* k = new double[3];
  55.     k[0] = AB.y / hypot(AB.x, AB.y) + AC.y / hypot(AC.x, AC.y);
  56.     k[1] = AB.x / hypot(AB.x, AB.y) + AC.x / hypot(AC.x, AC.y);
  57.     k[2] = k[1] * A.y - k[0] * A.x;
  58.     k[1] = -k[1];
  59.     return k;
  60. }
  61.  
  62.  
  63. int main() {
  64.     Point O;
  65.     double r, a, b, c;
  66.     cin >> O >> r >> a >> b >> c;
  67.     cout << fixed << setprecision(10);
  68.     double dist = (a * O.x + b * O.y + c) / hypot(a, b);
  69.     if (fabs(dist) > r)
  70.         cout << 0;
  71.     else
  72.         if (fabs(dist) == r) {
  73.             cout << 1 << endl;
  74.             Point M = Point(-a * dist / hypot(a, b) + O.x, O.y - b * dist / hypot(a, b));
  75.             cout << M;
  76.         }
  77.         else {
  78.             cout << 2 << endl;
  79.            
  80.             Point M = Point(-a * dist / hypot(a, b) + O.x, O.y - b * dist / hypot(a, b));
  81.  
  82.             if (M.x == O.x && M.y == O.y) {
  83.                 Vector norm = Vector(a, b);
  84.                 double a1 = b, b1 = -a;
  85.                 double c1 = - b * O.x + a * O.y;
  86.                 M = Point(-a1 * c1 / (a1 * a1 + b1 * b1), -b1 * c1 / (a1 * a1 + b1 * b1));
  87.                 if (a * M.x + b * M.y + c == 0) {
  88.                     M = Point(-a1 * c1 / (a1 * a1 + b1 * b1) - b1, a1 - b1 * c1 / (a1 * a1 + b1 * b1));
  89.                 }
  90.             }
  91.             Vector OM = Vector(O, M);      
  92.            
  93.             Vector OH = Vector(OM.x * r / hypot(OM.x, OM.y), OM.y * r / hypot(OM.x, OM.y));
  94.             Point H = Point(OH.x + O.x, OH.y + O.y);
  95.  
  96.             double cosAlpha = abs(dist / r);
  97.             double sinAlpha = sqrt(1 - cosAlpha * cosAlpha);
  98.  
  99.             Point K1 = Point(O.x + (H.x - O.x) * cosAlpha - sinAlpha * (H.y - O.y),
  100.                 O.y + (H.x - O.x) * sinAlpha + cosAlpha * (H.y - O.y));
  101.  
  102.             sinAlpha = -sinAlpha;
  103.  
  104.             Point K2 = Point(O.x + (H.x - O.x) * cosAlpha - sinAlpha * (H.y - O.y),
  105.                 O.y + (H.x - O.x) * sinAlpha + cosAlpha * (H.y - O.y));
  106.            
  107.             cout << K1 << endl << K2;          
  108.         }
  109.     return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement