Cho hai điểm A(x1,y1), B(x2,y2). Tìm phương trình đường thẳng dạng ax + by = c.
Công thức
a = y2 - y1b = x1 - x2c = a*x1 + b*y1
Mã nguồn C++
#include <iostream>
using namespace std;
void findLine(int points[2][2]) {
int a = points[1][1] - points[0][1];
int b = points[0][0] - points[1][0];
int c = a * points[0][0] + b * points[0][1];
cout << "(" << a << "x) + (" << b << "y) = (" << c << ")";
}
int main() {
int points[2][2] = {{5,9},{1,4}};
cout << "The equation of line is ";
findLine(points);
return 0;
}
Đầu ra
The equation of line is (-5x) + (4y) = (11)