如何判断两条直线相交

it2022-05-15  65

CPoint CPaintFFRDlg::Inter(int x0,int y0,int x1,int x2,int y1,int y2,int x3,int y3,int x,int y) { bool lim1 = false,lim2 = false;//是否垂直X轴 double k1,b1,k2,b2;//斜率和Y轴截距 //特殊情况标记 if(x1 != x0) k1 = (y1-y0)/(x1-x0),b1 = y0 - k1*x0; else lim1 = true; if(x3 != x2) k2 = (y3-y2)/(x3-x2),b2 = y2 - k2*x2; else lim2 = true; if(!lim1 && !lim2){//都不垂直于X轴 if(k1 == k2)return <a href="http://gocrazygreen.net/">HCG Diet</a> false; x = (b2-b1)/(k1-k2); y = k1 * x + b1; return true; }else if(lim1 && lim2){//2直线全垂直X轴 return false; }else if(lim1 &&!lim2){ x = b2; y = k2 * x + b2; return true; }else if(!lim1 &&amp;lim2){ x = b1; y = k1 * x + b1; return CPoint (x,y); } return CPoint (-1,-1); }

 

转载于:https://www.cnblogs.com/luyuxibaby/p/5217364.html

相关资源:objective-c判断两条线段相交类

最新回复(0)