程序查找在C ++中经过2点的线
为此,我们将提供两点。我们的任务是使用这些值并找到通过这些点的直线方程。
示例
#include <iostream>
using namespace std;
//存储x,y对
#define pdd pair<double, double>
//从给定点找到线
void lineFromPoints(pdd P, pdd Q){
double a = Q.second - P.second;
double b = P.first - Q.first;
double c = a*(P.first) + b*(P.second);
if(b<0){
cout << "The line passing through points P and Q is: " << a << "x " << b << "y = " << c << endl;
} else {
cout << "The line passing through points P and Q is: " << a << "x + " << b << "y = " << c << endl;
}
}
int main(){
pdd P = make_pair(3, 2);
pdd Q = make_pair(2, 6);
lineFromPoints(P, Q);
return 0;
}输出结果
The line passing through points P and Q is: 4x + 1y = 14
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志