在 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)
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP