公式如下:
若直线A1x十+B1y+十C1=0与直线A2x十+2y+十C2=0平行,则:
A1/A2=B1/B2≠C1/C2
①若B1=B2=0,此时两直线斜率不存在,满足:A1/A1=B1/B2≠C1/;C2;
②若B1≠0、B2≠0,此时也满足A1/A2=B1/B2≠C1/C2
则两直线平行,有:A1/A2=B1/B2≠C1/C2
上代码:
/*
*函数名:if_not_parallel
*功能:两条直线不垂直的情况下,判断是否相交
*输入:(x1,y1),(x2,y2)是线段一的两个端点的坐标
* (x3,y3),(x4,y4)是线段二的两个端点的坐标
*输出:返回整型值判断两条线段是否相交
*/
int if_intersect_np(double x1,double y1,double x2,double y2, double x3,double y3,double x4,double y4)
{
double x;
x=((x1*y2-x2*y1)/(x2-x1)+(x4*y3-x3*y4)/(x4-x3))/((y2-y1)/(x2-x1)-(y4-y3)/(x4-x3));
if(((x1-x)*(x-x2)>=0)&&((x3-x)*(x-x4)>=0))
return 1;
else
return 0;
}
网友评论