Advertisement
Guest User

Convex Quadrilateral

a guest
Nov 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. struct punct {
  7.     double x, y;
  8.     punct operator-(punct &B) {
  9.         punct R;
  10.         R.x = x - B.x;
  11.         R.y = y - B.y;
  12.         return R;
  13.     }
  14. };
  15.  
  16. double prod_scalar(punct &A, punct &B) {
  17.         return A.x * B.x + A.y * B.y;
  18. }
  19.  
  20. double f(double a, double b, double c) {
  21.     return a * a * (b * b + c * c - a * a);
  22. }
  23.  
  24. double dist(punct &A, punct &B) {
  25.     return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
  26. }
  27.  
  28. void baricentric(punct *A, double &u, double &v, double &w) {
  29.     punct v0 = A[1] - A[0], v1 = A[2] - A[0], v2 = A[3] - A[0];
  30.     /*double d00 = prod_scalar(v0, v0),
  31.     d01 = prod_scalar(v0, v1),
  32.     d11 = prod_scalar(v1, v1),
  33.     d20 = prod_scalar(v2, v0),
  34.     d21 = prod_scalar(v2, v1);
  35.     double det = d00 * d11 - d01 * d01,*/
  36.     double inv_det = 1.0 / (v0.x * v1.y - v1.x * v0.y);
  37.     v = (v2.x * v1.y - v1.x * v2.y) * inv_det;
  38.     w = (v0.x * v2.y - v2.x * v0.y) * inv_det;
  39.     u = 1.0 - v - w;
  40. }
  41.  
  42. int main()
  43. {
  44.     punct A[4], C;
  45.     for (int i = 0; i < 4; i++)
  46.         cin >> A[i].x >> A[i].y;
  47.     double u, v, w;
  48.     baricentric(A, u, v, w);
  49.     cout << u << ' ' << v << ' ' << w;
  50.     if (u > 0 && v < 0 && w > 0) {
  51.         cout << "abcd\n";
  52.     }
  53.     else {
  54.         cout << "Nu e convex";
  55.         return 0;
  56.     }
  57.     double a, b, c;
  58.     a = dist(A[0], A[1]);
  59.     b = dist(A[1], A[2]);
  60.     c = dist(A[0], A[2]);
  61.     C.x = f(a, b, c);
  62.     C.y = f(b, c, a);
  63.  
  64.     cout << C.x << ' ' << C.y << ' ' << f(c, a, b);
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement