Spicke

Треугольник

Apr 10th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. struct point { double x, y; };
  8.  
  9. // Читать координаты точки
  10. struct point get()
  11. {
  12.     struct point a;
  13.     cin >> a.x;
  14.     cin >> a.y;
  15.     return a;
  16. }
  17.  
  18. // Вычисляет положение точки D(xd,yd) относительно прямой AB
  19. double g(struct point a, struct point b, struct point d)
  20. {
  21.     return (d.x - a.x) * (b.y - a.y) - (d.y - a.y) * (b.x - a.x);
  22. }
  23.  
  24. // Лежат ли точки C и D с одной стороны прямой (AB)?
  25. bool f(struct point a, struct point b, struct point c, struct point d)
  26. {
  27.     return g(a, b, c) * g(a, b, d) >= 0;
  28. }
  29.  
  30. int main()
  31. {
  32.     setlocale(LC_ALL, "Rus");
  33.     struct point a = get(), b = get(), c = get(), d = get();
  34.     cout << (f(a, b, c, d) && f(b, c, a, d) && f(c, a, b, d) ? "yes" : "no") << endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment