程序查找在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 生日广州男生祝福语简短