程序查找在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
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便