Advertisement
allia

квадрат 1

Nov 15th, 2020 (edited)
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 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)
  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.   result.x = times.x*koeff;
  50.   result.x = head.x - result.x;
  51.  
  52.   result.y = times.y*koeff;
  53.   result.y = head.y - result.y;
  54.  
  55.   return result;
  56. }
  57.  
  58. int main ()
  59. {
  60.   vershina A, B, C, D;
  61.   cin >> A.x >> A.y >> B.x >> B.y;
  62.   direct AB, DB;
  63.  
  64.   double dlina = sqrt((A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y));
  65.  
  66.   AB = storona (A, B);
  67.   D = result(AB, A, dlina);
  68.   DB = storona (D, B);
  69.   C = result(DB, A, dlina*sqrt(2));
  70.  
  71.   cout << C.x << " " << C.y << " ";
  72.   cout << D.x << " " << D.y << " ";
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement