Determines whether the point in the matrix
Meaning of the questions:
given four points p2 (x1, y1) to the left-most point, p3 (x2, y2) is a point on the most, p1 (x3, y3) is the lowest point of, p4 (x4, y4) is rightmost point. Given a rectangular four points represented, to give a set point p (x, y), is determined p (x, y) in the rectangle whether
(Where p1, p2, p3, p4 are named for the convenience of my own name, mainly carried out in the name clockwise)
Solution:
you can use the dot or cross product to determine
(Image reproduced in: https://blog.csdn.net/faithmy509/article/details/82803646 )
Then the following code:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<map>
#define lowbit(x) x&(-x)
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const double pi=3.14159;
const int maxn=1e5;
const int mod=1e3;
struct node{
double x,y;
};
node p1,p2,p3,p4;
node p;
double getCross(node p1,node p2,node p){
return (p2.x-p1.x)*(p.y-p1.y)-(p.x-p1.x)*(p2.y-p1.y);
}
int main(){
cin>>p2.x>>p2.y;
cin>>p3.x>>p3.y;
cin>>p1.x>>p1.y;
cin>>p4.x>>p4.y;
cin>>p.x>>p.y;
if(getCross(p1,p2,p)*getCross(p3,p4,p)>=0&&getCross(p2,p3,p)*getCross(p4,p1,p)>=0){
printf("Yes\n");
}
else{
printf("No\n");
}
}