1.二维坐标系,输入点的坐标(xi, yi),判断点是否在三角形内
判断原理:若点p在三角形内,Sabc = Spab + Spac + Spbc;
struct point{
/*记录点的信息*/
double x;
double y;
};
struct v{
/*记录边的信息*/
point star;/*边的起点*/
point en;/*边的终点*/
};
struct triangle{
/*记录三角形信息*/
point A;/*三角形的顶点A*/
point B;/*三角形的顶点B*/
point C;/*三角形的顶点C*/
};
triangle tre[104];
int tr;
double crossProduct(v * v1, v * v2);/*向量叉积*/
bool inTrianle(triangle t, point P);/*判断点是否在三角形内*/
double crossProduct(v * v1, v * v2){
v vt1, vt2;
double result = 0