天天看點

四點确定的兩條直線求交點坐标方法

// 計算兩直線的交點x坐标

private float crossPointX(float line1x1, float line1y1, float line1x2,

float line1y2, float line2x1, float line2y1, float line2x2,

float line2y2) {

float x = (line1x1 * (line1y2 - line1y1) / (line1x2 - line1x1)

- line2x1 * (line2y2 - line2y1) / (line2x2 - line2x1) + line2y1 - line1y1)

/ ((line1y2 - line1y1) / (line1x2 - line1x1) - (line2y2 - line2y1)

/ (line2x2 - line2x1));

return x;

}

// 計算兩直線的交點y坐标

private float crossPointY(float linex1, float liney1, float linex2,

float liney2, float x) {

float y = (liney2 - liney1) * (x - linex1) / (linex2 - linex1) + liney1;

return y;

繼續閱讀