Advertisement
allia

треугольник вариант 1

Nov 13th, 2020
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7. #define PI 3.14159265  
  8. struct otrezok
  9. {
  10.   double x1, y1, x2, y2, x, y;
  11.   double length;
  12. };
  13.  
  14. struct vershina
  15. {
  16.   double x, y;
  17. };
  18.  
  19. vershina yravnenie(double a, double b, double c, double m)
  20. {
  21.   double x1=0, x2=0, D=0, x = 0, y = 0;
  22.  
  23.   if ((b==0) && (c==0))
  24.       x = 1;
  25.   else
  26.      {
  27.       D = b*b - 4*a*c;
  28.              x1=(-b+sqrt(D))/2/a;
  29.              x2=(-b-sqrt(D))/2/a;
  30.               if (x1==x2)
  31.                 x = x1;
  32.               else
  33.                 {
  34.                   if (x1 < x2)
  35.                    x = x2;
  36.                   else x = x1;
  37.                 }
  38.       }
  39.  
  40.   y = (m+b/2/m*x)/b*2*m;
  41.   vershina C;
  42.   C.x = x;
  43.   C.y = y;
  44.   return C;
  45. }
  46.  
  47. int main ()
  48. {
  49.   otrezok AB, BC;
  50.   double ygol_B;
  51.   cin >> AB.length >> BC.length >> ygol_B;
  52.   vershina B;
  53.  
  54.   B.x = 0;
  55.   B.y = 0;
  56.  
  57.   AB.x = -sqrt(AB.length*AB.length/2);
  58.   AB.y = -AB.x;
  59.  
  60.   double m = AB.length*BC.length*cos(ygol_B*PI/180.0);
  61.   double AC_2 = AB.length*AB.length + BC.length*BC.length - 2*m;
  62.   double a = 2*AB.x*AB.x;
  63.   double b = -2*m*AB.x;
  64.   double c = m*m - b*AB.y + 2*pow(AB.x, 4) - AC_2*a/2;
  65.   vershina C = yravnenie(a, b, c, m);
  66.  
  67.   cout.precision(6);
  68.   cout << fixed << B.x << " " << B.y << endl;
  69.   cout << fixed << AB.x << " " << AB.y << endl;
  70.   cout << fixed << C.x << " " << C.y << " ";
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement