Advertisement
allia

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

Nov 17th, 2020 (edited)
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. struct otrezok
  8. {
  9.   public:
  10.   double x1, y1, x2, y2, x, y;
  11.   double length;
  12.  
  13.   otrezok(double x1, double x2,double  y1,double y2)
  14.   {
  15.    length = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
  16.   }
  17. };
  18.  
  19. struct ygol
  20. {
  21.  double a;
  22.  double cos_ygl, sin_ygl, tg_ygl;
  23.  
  24. ygol (double a)
  25.  {
  26.   cos_ygl = cos(a*3.141592653/180.0);
  27.   sin_ygl = sin(a*3.141592653/180.0);
  28.  
  29.   if (cos_ygl !=0 )
  30.     tg_ygl  = sin_ygl/cos_ygl;
  31.   else tg_ygl = INT16_MAX;
  32.  }
  33. };
  34.  
  35. struct direct
  36. {
  37.  double k = 0, b = 0;
  38.  double parametr = INT16_MAX;
  39. };
  40.  
  41. struct vershina
  42. {
  43.    double x, y;
  44.   vershina()
  45.   {
  46.     x = 0;
  47.     y = 0;
  48.   }
  49. };
  50.  
  51. direct stright(vershina one, double k)
  52. {
  53.   direct stright;
  54.  
  55.   if (k != INT16_MAX)
  56.     {
  57.       stright.k = k;
  58.       stright.b = one.y - stright.k*one.x;
  59.     }
  60.   else stright.parametr = one.x;
  61.  
  62.   return stright;
  63. }
  64. double koeff (otrezok a, otrezok b, ygol A, double mediana)
  65. {
  66.   double mediana_1;
  67.   mediana_1 = sqrt(a.length*a.length + b.length*b.length/4 - a.length*b.length*A.cos_ygl);
  68.   double koeff = mediana/mediana_1;
  69.   return koeff;
  70. }
  71.  
  72. vershina otvet (direct normal_1, direct normal_2)
  73. {
  74.  vershina otvet;
  75.  if (normal_1.parametr == INT16_MAX && normal_2.parametr == INT16_MAX)
  76.  {
  77.    otvet.x = (normal_2.b - normal_1.b)/(normal_1.k - normal_2.k);
  78.    otvet.y = normal_1.k*otvet.x + normal_1.b;
  79.  }
  80.  else if (normal_1.parametr != INT32_MAX)
  81.  {
  82.    otvet.x = normal_1.parametr;
  83.    otvet.y = normal_2.k*otvet.x + normal_2.b;
  84.  }
  85.  else if (normal_2.parametr != INT16_MAX)
  86.  {
  87.    otvet.x = normal_2.parametr;
  88.    otvet.y = normal_1.k*otvet.x + normal_1.b;
  89.  }
  90.  return otvet;
  91. };
  92.  
  93.  int main ()
  94. {
  95.   vershina A, B, C, B_1, C_1, seredina_AB;
  96.   double  mediana, a, b;
  97.  
  98.   cin >> mediana >> a >> b;
  99.  
  100.   ygol ygol_A(a);
  101.   ygol ygol_B(b);
  102.  
  103.   B_1.x = 100;
  104.  
  105.  direct AC = stright(A, ygol_A.tg_ygl);
  106.  direct BC = stright(B_1, -ygol_B.tg_ygl);
  107.  
  108.  C_1 = otvet(AC, BC);
  109.  
  110.  otrezok AB_1(A.x, B_1.x,  A.y, B_1.y);
  111.  otrezok AC_1 (A.x, C_1.x, A.y, C_1.y);
  112.  
  113.  B.x = koeff(AC_1, AB_1, ygol_A, mediana)*B_1.x;
  114.  
  115.  BC = stright(B, -ygol_B.tg_ygl);
  116.  C = otvet(AC, BC);
  117.  
  118.  cout.precision(8);
  119.  cout << fixed << A.x << " " << A.y << endl;
  120.  cout << fixed << B.x << " " << B.y << endl;
  121.  cout << fixed << C.x << " " << C.y << " ";
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement