c++已知两条直线及其每条上的两点坐标,求交点坐标,有没有更简单的算法?

 我来答
匿名用户
2013-05-13
展开全部
#include "stdafx.h"
#include <iostream>
using namespace std;void MyF(int a1,int b1,int c1,int a2,int b2,int c2)
{
if((a1*b2)!=(a2*b1))
cout<<"Line1 and Line2 had the intersection: ("<<(double)((double)(b1*c2-b2*c1)/(double)(a1*b2-a2*b1))<<","<<(double)((double)(a1*c2-a2*c1)/(double)(a2*b1-a1*b2))<<")\n";
else if(((double)(a1/a2)==(double)(b1/b2))&&((double)(b1/b2)==(double)(c1/c2)))
cout<<"Line1 is same as Line2!";
else
cout<<"Line1 and Line2 had no intersection!";
}int main(int argc, char* argv[])
{
int a1,a2,b1,b2,c1,c2;
cout<<"input line1 x's coef:";
cin>>a1;
cout<<"\ninput line1 y's coef:";
cin>>b1;
cout<<"\ninput line1's constant:";
cin>>c1;
cout<<"\nLine1:"<<a1<<"x+"<<b1<<"y+"<<c1<<"=0"<<endl;
cout<<"input line2 x's coef:";
cin>>a2;
cout<<"\ninput line2 y's coef:";
cin>>b2;
cout<<"\ninput line2's constant:";
cin>>c2;
cout<<"\nLine2:"<<a2<<"x+"<<b2<<"y+"<<c2<<"=0"<<endl;
MyF(a1,b1,c1,a2,b2,c2);
return 0;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式