Advertisement
allia

центр вписанной окружности

Nov 12th, 2020
1,411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. struct otrezok
  8. {
  9.   double x1, y1, x2, y2;
  10.   double length;
  11.  
  12.   void dlina (double x, double y, double x2_1, double y2_1)
  13.  {
  14.    x1 = x;
  15.    y1 = y;
  16.    x2 = x2_1;
  17.    y2 = y2_1;
  18.    length = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
  19.  }
  20. };
  21.  
  22. struct vershina
  23. {
  24.   double x, y;
  25. };
  26.  
  27. struct direct
  28. {
  29.  double a = 0, b = 0;
  30.  double parametr = 0;
  31. };
  32.  
  33. otrezok sozdanie(vershina one, vershina two)
  34. {
  35.   otrezok a;
  36.   a.dlina(one.x, one.y, two.x, two.y);
  37.   return a;
  38. }
  39.  
  40. direct result(vershina one, vershina two)
  41. {
  42.   direct stright;
  43.   if(two.x - one.x != 0)
  44.   {
  45.     stright.a = (one.y - two.y)/(one.x - two.x);
  46.     stright.b = one.y - stright.a*one.x;
  47.   }
  48.   else stright.parametr = one.x;
  49.   return stright;
  50. }
  51.  
  52. vershina point (vershina one, vershina two, otrezok left, otrezok right, otrezok a)
  53. {
  54.   vershina point_bissek;
  55.   double m = left.length*a.length/(right.length+left.length);
  56.   double n = a.length - m;
  57.   point_bissek.x = (n*one.x+m*two.x)/(n+m);
  58.   point_bissek.y = (n*one.y+m*two.y)/(n+m);
  59.   //cout << point_bissek.x << " " << point_bissek.y << endl;
  60.   return point_bissek;
  61. }
  62.  
  63. vershina otvet (direct bissek_1, direct bissek_2)
  64. {
  65.  vershina otvet;
  66.  
  67.  if (bissek_1.parametr == 0 && bissek_2.parametr == 0)
  68.    {
  69.      otvet.x = (bissek_2.b - bissek_1.b)/(bissek_1.a - bissek_2.a);
  70.      otvet.y = bissek_1.a*otvet.x + bissek_1.b;
  71.    }
  72.    else if (bissek_1.parametr != 0)
  73.    {
  74.      otvet.x = bissek_1.parametr;
  75.      otvet.y = bissek_2.a*otvet.x + bissek_2.b;
  76.    }
  77.    else
  78.    {
  79.      otvet.x = bissek_2.parametr;
  80.      otvet.y = bissek_1.a*otvet.x + bissek_1.b;
  81.    }
  82.  
  83.  return otvet;
  84. };
  85.  
  86. int main ()
  87. {
  88.   vershina A, B, C;
  89.   cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y;
  90.  
  91.   otrezok *arr = new otrezok[3];
  92.  
  93.     arr[0] = sozdanie(A, B);
  94.     arr[1] = sozdanie(B, C);
  95.     arr[2] = sozdanie(A, C);
  96.  
  97.   vershina peresech_AB = point(A, B, arr[2], arr[1], arr[0]);
  98.   vershina peresech_BC = point(B, C, arr[0], arr[2], arr[1]);
  99.  
  100.   direct bissek_A = result(A, peresech_BC);
  101.   direct bissek_C = result(C, peresech_AB);
  102.  
  103.   cout.precision(6);
  104.   cout << fixed << otvet(bissek_A, bissek_C).x << " ";
  105.   cout << fixed << otvet(bissek_A, bissek_C).y;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement