公式: 以三角形两边的平行四边形面积等于两边向量叉乘
三角形三个顶点如果顺时针那么面积为负,逆时针为正
判断点o是否在三角形abc内部当且仅当 Sabc == Soab + Sobc + Soac
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1005;
const int inf = 1<<30;
int n,pos;
double area( double x0,double y0,double x1,double y1,double x2,double y2 )
{
return x0*y1 + x2*y0 + x1*y2 - x2*y1 - x0*y2 - x1*y0;
}
int main()
{
//freopen("data.txt","r",stdin);
double x[5],y[5];
for( int i = 0; i < 4; i ++ )
scanf("%lf%lf",&x[i],&y[i]);
printf("%lf\n",area(x[0],y[0],x[1],y[1],x[2],y[2])); //三角形面积的2倍
//在三角形内部的话Soab + Sobc + Soac == Sabc
printf("%lf\n",area(x[0],y[0],x[1],y[1],x[3],y[3]) + area(x[2],y[2],x[0],y[0],x[3],y[3]) + area(x[1],y[1],x[2],y[2],x[3],y[3]) );
return 0;
}