Advertisement
allia

высоты

Nov 12th, 2020 (edited)
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. struct vershina
  8. {
  9.   double x, y;
  10. };
  11.  
  12. struct direct
  13. {
  14.  double k = 0, b = 0;
  15.  double parametr = 0;
  16. };
  17.  
  18. direct normal (direct one, vershina trig)
  19. {
  20.   direct normal;
  21.   if (one.parametr == 0 && one.k != 0)
  22.   {
  23.     normal.k = -1/one.k;
  24.     normal.b = trig.y - normal.k*trig.x;
  25.   }
  26.   else if (one.parametr != 0)
  27.   {
  28.     normal.k = 0;
  29.     normal.b = trig.y;
  30.   }
  31.   else if (one.k == 0)
  32.     normal.parametr = trig.x;
  33.   //cout << normal.k << "x + " << normal.b << " " << normal.parametr << endl;
  34.   return normal;
  35. }
  36.  
  37. direct stright(vershina one, vershina two)
  38. {
  39.   direct stright;
  40.   if(two.x - one.x != 0)
  41.   {
  42.     stright.k = (one.y - two.y)/(one.x - two.x);
  43.     stright.b = one.y - stright.k*one.x;
  44.   }
  45.   else stright.parametr = one.x;
  46.   return stright;
  47. }
  48.  
  49. vershina otvet (direct normal_1, direct normal_2)
  50. {
  51.  vershina otvet;
  52.  if (normal_1.parametr == 0 && normal_2.parametr == 0)
  53.  {
  54.    otvet.x = (normal_2.b - normal_1.b)/(normal_1.k - normal_2.k);
  55.    otvet.y = normal_1.k*otvet.x + normal_1.b;
  56.  }
  57.  else if (normal_1.parametr != 0)
  58.  {
  59.    otvet.x = normal_1.parametr;
  60.    otvet.y = normal_2.k*otvet.x + normal_2.b;
  61.  }
  62.  else if (normal_2.parametr != 0)
  63.  {
  64.    otvet.x = normal_2.parametr;
  65.    otvet.y = normal_1.k*otvet.x + normal_1.b;
  66.  }
  67.  return otvet;
  68. };
  69.  
  70. int main ()
  71. {
  72.   vershina A, B, C;
  73.   cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y;
  74.  
  75.   direct AB = stright(A, B);
  76.   direct BC = stright(B, C);
  77.  
  78.   direct normal_one = normal(AB, C);
  79.   direct normal_two = normal(BC, A);
  80.  
  81.   cout.precision(10);
  82.   cout << fixed << otvet(normal_one, normal_two).x << " ";
  83.   cout << fixed << otvet(normal_one, normal_two).y;
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement