计算几何模板 if( (a.y2-a.y1)*(b.x2-b.x1)==(b.y2-b.y1)*(a.x2-a.x1) ) //向量判别是否平行 x1y2=x2y1 { if( (a.y1-b.y2)*(a.x2-b.x1)==(a.y2-b.y1)*(a.x1-b.x2) && (b.y1-a.y1)*(a.x2-b.x2)==(a.y2-b.y2)*(b.x1-a.x1) ) printf("共线\n"); else printf("平行\n"); } 叉积 (2*S) int det(int x1,int y1,int x2, int y2) { retur n x1*y2 - x2*y1; } n x1*y2 - x2*y1; }