Advertisement
allia

последний треугольник

Nov 16th, 2020
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 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 x, y;
  10.   double length;
  11. };
  12.  
  13. struct direct
  14. {
  15.  double k = 0, b = 0;
  16.  double parametr = INT32_MAX;
  17. };
  18.  
  19. struct vershina
  20. {
  21.   double x, y;
  22. };
  23.  
  24. direct stright(vershina one, double k)
  25. {
  26.   direct stright;
  27.  
  28.   if (k != INT32_MAX)
  29.     {
  30.       stright.k = k;
  31.       stright.b = one.y - stright.k*one.x;
  32.     }
  33.   else stright.parametr = one.x;
  34.  
  35.   return stright;
  36. }
  37.  
  38. double sozdanie(double a, double b, double c)
  39. {
  40.   double itog;
  41.   double cos_itog = (b*b + c*c - a*a)/2/b/c;
  42.   double sin_itog = sqrt(1 - cos_itog*cos_itog);
  43.   double tg_itog;
  44.  
  45.   if (cos_itog != 0)
  46.     tg_itog = sin_itog/cos_itog;
  47.   else tg_itog = INT32_MAX;
  48.  
  49.   return tg_itog;
  50. }
  51.  
  52. vershina otvet (direct normal_1, direct normal_2)
  53. {
  54.   //cout << normal_1.k << "x + " << normal_1.b << " " << normal_1.parametr << endl;
  55.  vershina otvet;
  56.  if (normal_1.parametr == INT32_MAX && normal_2.parametr == INT32_MAX)
  57.  {
  58.    otvet.x = (normal_2.b - normal_1.b)/(normal_1.k - normal_2.k);
  59.    otvet.y = normal_1.k*otvet.x + normal_1.b;
  60.  }
  61.  else if (normal_1.parametr != INT32_MAX)
  62.  {
  63.    otvet.x = normal_1.parametr;
  64.    otvet.y = normal_2.k*otvet.x + normal_2.b;
  65.  }
  66.  else if (normal_2.parametr != INT32_MAX)
  67.  {
  68.    otvet.x = normal_2.parametr;
  69.    otvet.y = normal_1.k*otvet.x + normal_1.b;
  70.  }
  71.  return otvet;
  72. };
  73.  
  74.  int main ()
  75. {
  76.   direct BC, AC;
  77.   vershina A, B, C;
  78.   double a, b, c, dlina_AB, dlina_BC, dlina_AC;
  79.   cin >> dlina_AB >> dlina_AC >> dlina_BC;
  80.  
  81.   A.x = 0;
  82.   A.y = 0;
  83.   B.x = dlina_AB;
  84.   B.y = 0;
  85.  
  86.   double tg_A = sozdanie( dlina_BC, dlina_AB, dlina_AC);
  87.   double tg_B = sozdanie( dlina_AC, dlina_BC, dlina_AB);
  88.  
  89.   if (tg_B != INT32_MAX)
  90.    tg_B = -tg_B;
  91.  
  92.   AC = stright(A, tg_A);
  93.   BC = stright(B, tg_B);
  94.  
  95.   C = otvet(AC, BC);
  96.  
  97. cout.precision(10);
  98.  cout << fixed << A.x << " " << A.y << endl;
  99.  cout << fixed << B.x << " " << B.y << endl;
  100.  cout << fixed << C.x << " " << C.y << " ";
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement