C++ 等分三点圆 源代码
时间: 2023-06-23 21:53:12 浏览: 91
以下是一个简单的 C++ 源代码,用于计算等分三点圆的坐标:
```cpp
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x1, y1, x2, y2, x3, y3;
cout << "请输入三个点的坐标(x1,y1,x2,y2,x3,y3):" << endl;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a = x2 - x1;
double b = y2 - y1;
double c = x3 - x1;
double d = y3 - y1;
double e = a * (x1 + x2) + b * (y1 + y2);
double f = c * (x1 + x3) + d * (y1 + y3);
double g = 2.0 * (a * (y3 - y2) - b * (x3 - x2));
if (g == 0) {
cout << "三点共线,无法构成等分三点圆!" << endl;
return 0;
}
double centerX = (d * e - b * f) / g;
double centerY = (a * f - c * e) / g;
double radius = sqrt((x1 - centerX) * (x1 - centerX) + (y1 - centerY) * (y1 - centerY));
cout << "等分三点圆的圆心坐标为(" << centerX << ", " << centerY << ")" << endl;
cout << "等分三点圆的半径为" << radius << endl;
return 0;
}
```
这段代码使用输入的三个点的坐标计算等分三点圆的圆心坐标和半径,并输出结果。
阅读全文