Question: Give the three points of a triangle, and then give the third point to determine whether the point is within the triangle.
Method: Obtain the area of the triangle, and then obtain the area of the triangle composed of each of the points in the test point and the triangle. If the area is equal to the area of the top triangle after the sum, it is within the triangle, otherwise, it does not exist.
Note: When the test point is displayed on one side of a triangle, the area of the triangle formed by the test point and other points cannot be 0.
Code:
#include
#include
#include
#include
using namespace std;int solve(int a1,int b1,int a2,int b2,int a3,int b3){ int sum=0; sum+=a1*b2-a2*b1; sum+=a2*b3-a3*b2; sum+=a3*b1-a1*b3; return abs(sum);}int main(){ int x[3],y[3],l,r; while(1) { for(int i=0;i<3;i++) cin>>x[i]>>y[i]; cin>>l>>r; if(x[0]==0&&x[1]==0&&x[2]==0&&y[0]==0&&y[1]==0&&y[2]==0&&l==0&&r==0) break; int s1=solve(x[0],y[0],x[1],y[1],x[2],y[2]); int s2=solve(x[0],y[0],x[1],y[1],l,r); int s3=solve(x[0],y[0],l,r,x[2],y[2]); int s4=solve(l,r,x[1],y[1],x[2],y[2]); if(s1==s2+s3+s4&&s2&&s3&&s4) cout<<"YES\n"; else cout<<"NO\n"; } return 0;}