在C ++中使用直径端点找到圆心
假设我们有两个直径为圆的端点。它们是(x1,y1)和(x2,y2),我们必须找到圆心。因此,如果两个点分别是(-9,3)和(5,-7),则中心位于位置(-2,-2)。
我们知道两点的中点是-
$$(x_{m},y_{m})=\left(\frac{(x_{1}+x_{2})}{2},\frac{(y_{1}+y_{2})}{2}\right)$$
示例
#include<iostream>
using namespace std;
class point{
public:
float x, y;
point(float x, float y){
this->x = x;
this->y = y;
}
void display(){
cout << "(" << x << ", " <<y<<")";
}
};
point center(point p1, point p2) {
int x, y;
x = (float)(p1.x + p2.x) / 2;
y = (float)(p1.y + p2.y) / 2;
point res(x, y);
return res;
}
int main() {
point p1(-9.0, 3.0), p2(5.0, -7.0);
point res = center(p1, p2);
cout << "Center is at: ";
res.display();
}输出结果
Center is at: (-2, -2)
热门推荐
1 如何训练狗狗握手
10 新员工寄语祝福语简短
11 新婚敬酒祝福语大全简短
12 怎么训练狗狗
13 训练狗狗上厕所
14 春蚕老师祝福语简短励志
15 高考好运如愿祝福语简短
16 战哥过年祝福语简短
17 中考感谢朋友祝福语简短
18 长沙旅游祝福语大全简短