如何求两条线的交叉点坐标?

来源:互联网  时间:2016/6/21 6:05:58

关于网友提出的“ 如何求两条线的交叉点坐标?”问题疑问,本网通过在网上对“ 如何求两条线的交叉点坐标?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 如何求两条线的交叉点坐标?
描述:

已知两条线line1(x1,y1,x2,y2),line2(x1,y1,x2,y2),如何判断这两条线是否相交,如果相交,则求出交叉点的坐标?
希望大家帮忙解决!!


解决方案1:

基本思路:
直线方程:
aX+b = y
把两点坐标带入得到a,b的值
得到两条直线的直线方程
将两条直线的方程连立方程组求解,解为焦点坐标。
以下Sample.不过这种东西自己复习一下应该就可以搞定。初中数学问题。。。。。。。
public class Intersection 

public static double[] getIntersection(double a1,double b1,double c1, 
double a2,double b2,double c2) 

double[] res=new double[2]; 
res[0]=(c1*b2-c2*b1)/(a1*b2-a2*b1); 
res[1]=(a1*c2-a2*c1)/(a1*b2-a2*b1); 
return res; 

public static double[] getIntersection(double[] fun1,double[] fun2) 

if(fun1.length!=3||fun2.length!=3) 
return null; 
else 
return getIntersection(fun1[0],fun1[1],fun1[2], 
fun2[0],fun2[1],fun2[2]); 

public static void main(String[] args) 

double[] f1={2.0312,-1.0,-24.6972}; 
double[] f2={-0.4073,-1.0,-0.6230}; 
double[] f3={-0.995,-1.0,0}; 
double[] res=getIntersection(f3,f2); 
for(double r:res) 
System.out.println (r); 

}

上一篇random for a series of random numbers??????
下一篇很怪异的问题,用同样的方法,第一个通过,第二个就出异常,求救
明星图片
相关文章
《 如何求两条线的交叉点坐标?》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)