Advertisement
allia

квадрат 2 (12)

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