Task Description
Given a convex quadrilateral , please determine if the origin is with . For example, if has four corners , , , and then the answer is yes. If is , , , and then the answer is no.
給一個凸四邊形 的四個頂點座標,請問原點 是否在四邊形內部,如果原點在四邊形內部,輸出 1
,反之,請輸出 0
。
Input
The input consists of eight integers, , and , representing the four corners , and in counterclockwise order. It is guaranteed that the four sides of the will not be parallel to either x or y axis, and will not contain the origin. The absolute value of all numbers is no more than 100.
輸入包含八個整數 ,按照逆時針順序給定座標 。請注意:四邊形的邊不一定平行於座標兩軸,座標的絕對值小於等於 。
Output
The output is either 1
or 0
, representing that the origin is within or not within .
Sample Input 1
2 1 -1 2 -2 -1 -1 -3
Sample Output 1
1
Sample Input 2
12 1 9 2 8 -1 9 -3
Sample Output 2
0
Hint 1
In computational geometry of the plane, the cross product is used to determine the sign of the acute angle defined by three points , and . It corresponds to the direction of the cross product of the two coplanar vectors defined by the pairs of points and , i.e., by the sign of the expression ... Cross product Computational geometry - wiki
For sample input 1, we get four vectors .
Origin in if and only if it must satisfy that , , , and
Hint 2
Ray casting algorithm - Wiki / Convex Polygon
Hint 3
Area summation method (Note: Be careful about arithmetic overflow)