回覆列表
  • 1 # dhfhm2115

    //判斷兩條直線段是否有交點,有則計算交點的座標//p1,p2是直線一的端點座標//p3,p4是直線二的端點座標booldetectIntersect(Pointp1,Pointp2,Pointp3,Pointp4){doubleline_x,line_y;//交點if((fabs(p1.x-p2.x)<1e-6)&&(fabs(p3.x-p4.x)<1e-6)){returnfalse;}elseif((fabs(p1.x-p2.x)<1e-6))//如果直線段p1p2垂直與y軸{if(between(p1.x,p3.x,p4.x)){doublek=(p4.y-p3.y)/(p4.x-p3.x);line_x=p1.x;line_y=k*(line_x-p3.x)+p3.y;if(between(line_y,p1.y,p2.y)){returntrue;}else{returnfalse;}}else{returnfalse;}}elseif((fabs(p3.x-p4.x)<1e-6))//如果直線段p3p4垂直與y軸{if(between(p3.x,p1.x,p2.x)){doublek=(p2.y-p1.y)/(p2.x-p1.x);line_x=p3.x;line_y=k*(line_x-p2.x)+p2.y;if(between(line_y,p3.y,p4.y)){returntrue;}else{returnfalse;}}else{returnfalse;}}else{doublek1=(p2.y-p1.y)/(p2.x-p1.x);doublek2=(p4.y-p3.y)/(p4.x-p3.x);if(fabs(k1-k2)<1e-6){returnfalse;}else{line_x=((p3.y-p1.y)-(k2*p3.x-k1*p1.x))/(k1-k2);line_y=k1*(line_x-p1.x)+p1.y;}if(between(line_x,p1.x,p2.x)&&between(line_x,p3.x,p4.x)){returntrue;}else{returnfalse;}}}

  • 中秋節和大豐收的關聯?
  • 氨基酸的氨基端親水還是疏水?