Advertisement
kirya_shkolnik

Лежит точка внутри треугольника

Dec 9th, 2020 (edited)
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. double area(double ax,double ay,double bx,double by,double cx,double cy) {
  6.     return abs((by-ay)*(cx-ax)-(bx-ax)*(cy-ay));
  7. }
  8. bool resh(double ax, double ay, double bx, double by, double cx, double cy, double px, double py){
  9.     double s=area(ax,ay,bx,by,cx,cy),s1=area(ax,ay,bx,by,px,py),s2=area(bx,by,cx,cy,px,py),s3=area(cx,cy,ax,ay,px,py);
  10.     if (s1+s2+s3-s<=0) return true; else return false;
  11. }
  12. int main()
  13. {
  14.     double pointx, pointy;
  15.     cin >> pointx >> pointy;
  16.     // resh(точка A, точка B, точка C, произвольная точка)   ( по две координаты)
  17.     if(resh(1,1,2,1,1.5,2,pointx, pointy) or resh(1,2,2,2,1.5,3,pointx, pointy) or resh(1,3,2,3,1.5,4,pointx, pointy)) cout << "Yes";
  18.  
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement